The compare() method of java.text.RuleBasedCollator class is used to compare the strength of two objects and it will return 0, positive and negative value as an output according to the result.
public int compare(Object o1, Object o2)
Parameter: This method takes two objects between which comparison is going to take place.
Return Value: if the first object is equals, grater or lesser than the other object than it will return zero, positive and negative value respectively.
Exception: This method throws NullPointerException if one of the argument is null.
Below are the examples to illustrate the compare() method:
ab is less than Ab
one of the object is null java.lang.NullPointerException
- RuleBasedCollator getRules() method in Java with Example
- RuleBasedCollator hashCode() method in Java with Example
- RuleBasedCollator getCollationKey() method in Java with Example
- RuleBasedCollator equals() method in Java with Example
- RuleBasedCollator clone() method in Java with Example
- RuleBasedCollator getCollationElementIterator(CharacterIterator) method in Java
- RuleBasedCollator getCollationElementIterator(String) method in Java
- Short compare() method in Java
- Java Integer compare() method
- How compare() method works in Java
- Double compare() Method in Java with Examples
- Float compare() Method in Java with Examples
- Boolean compare() method in Java with Examples
- Byte compare() method in Java with examples
- Java Guava | Ints.compare() method with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.