answersLogoWhite

0


Best Answer

To compare the contents of two objects. The equality, "=", will simply tell you whether two objects are in the same memory location; it doesn't tell you whether their contents are actually the same. To compare the contents, there is an equals() method which tells you whether the contents are actually equal; there is also a compareTo() which can also tell you which of two objects is "greater". Since objects can be quite complex, the programmer may have to overwrite the (often useless) default behavior of these methods.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the use of 'compareTo' in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering
Related questions

What are some ways in order to perform String comparison in Java?

String comparison in Java features four ways. These ways are String comparison using equals method, equalsIgnoreCase method, CompareTo method, and CompareToIgnoreCase method.


Can you write the code to compare 2 string objects in Java?

In java, the String object has a compareTo() method. The method returns an int. If the int is less than zero, the first string is less than the second. If the int is greater, the first is greater than the second. If the int is zero, the two strings are equal.


Can you use pointers in java?

Java does not support Pointers and hence you cannot use it in Java.


How efficiently to compare 2 HashSets in Java without to use foreach cycle?

If you want to compare two HashSet objects, you have very few choices. The obvious choice is to use the .equals method built into the implementation. If that doesn't work for you, then you have to use the Iterator returned by the .iterator method, which is functionally the same as using the for-each loop.The Comparable Interface can be used to compare two hashsets.Use compareTo() method.


What technologies link to Java?

Java is exclusive to surfing the web. Some web sites use Java to embed videos, others use Java for advertisements.


Does Java Script use the same compiler as Java?

No


What you use in case of pointer in java?

Java does not have pointers


What is java 7?

Java 7 is the most current version of Java. Many movies and games use Java.


Which is the best Book to understand JAVA in short?

You can use Head First Java or Java Complete Reference to learn Java.


Do you have to use java?

Not usually. There are numerous languages out there with similar functionality. The only time you must use Java is if your employer or client demands that a project be done in Java, or a particular platform requires the use of Java, such as Android OS.


How do you script a RuneScape bot?

RuneScape bots use Java. Use a Java Binary Code.


Why you not use clrscr in java?

Many reasons, one of them: there is no 'clrscr' in Java.