About 1,470,000 results
Open links in new tab
  1. What do the return values of Comparable.compareTo mean in Java?

    Sep 13, 2018 · the Object Ordering section of the Collection Trail in the Sun Java Tutorial Effective Java by Joshua Bloch, especially item 12: Consider implementing Comparable Java …

  2. java - Comparing strings by their alphabetical order - Stack Overflow

    May 27, 2017 · Note that String#compareTo 's lexicographic comparison will sort capital "Z" before lower-case "a." If you're alphabetizing mixed-case strings, you need locale-sensitive …

  3. How to implement compareTo method in Java and what does it …

    May 8, 2022 · The compareTo method in your example specifies that when we compare two spaceships we are going to use the string value of their spaceshipClass. Furthermore, the …

  4. java - What is the difference between compare () and compareTo ...

    Jan 7, 2009 · compareTo(T object) comes from the java.lang.Comparable interface, implemented to compare this object with another to give a negative int value for this object being less than, …

  5. java - How does compareTo work? - Stack Overflow

    Comparison using compareTo does not use correlation: correlation is a symmetric property, whereas compareTo is (or at least should be) anti-symmetric, at least in the sense that …

  6. How to use the Comparable CompareTo on Strings in Java

    Sep 20, 2010 · How to use the Comparable CompareTo on Strings in Java Asked 15 years, 2 months ago Modified 5 years ago Viewed 96k times

  7. How to compare dates in Java? - Stack Overflow

    Feb 22, 2010 · How do I compare dates in between in Java? Example: date1 is 22-02-2010 date2 is 07-04-2010 today date3 is 25-12-2010 date3 is always greater than date1 and date2 is …

  8. How do I compare strings in Java? - Stack Overflow

    Apr 2, 2013 · Option 3: Java String comparison with the compareTo method There is also a third, less common way to compare Java strings, and that's with the String class compareTo method.

  9. java - How to use comparison operators like >, =, < on BigDecimal ...

    Jan 8, 2016 · Every object of the Class BigDecimal has a method compareTo you can use to compare it to another BigDecimal. The result of compareTo is then compared > 0, == 0 or < 0 …

  10. java - How to use compareTo () to compare two objects? - Stack …

    Nov 17, 2021 · It's a good practice to implement compareTo method such that, when its return value is 0, it's like two objects are equals (e.g. firstK.compareTo(secondK) == …