About 52 results
Open links in new tab
  1. What is the difference between compare () and compareTo ()?

    Jan 7, 2009 · 2 compareTo() is called on one object, to compare it to another object. compare() is called on some object to compare two other objects. The difference is where the logic that does actual …

  2. 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 sign(a.compareTo(b)) …

  3. java - compareTo () vs. equals () - Stack Overflow

    Oct 11, 2019 · 10 compareTo() not only applies to Strings but also any other object because compareTo<T> takes a generic argument T. String is one of the classes that has implemented the …

  4. What do the return values of Comparable.compareTo mean in Java?

    Sep 22, 2010 · What is the difference between returning 0, returning 1 and returning -1 in compareTo() in Java?

  5. String Comparison in Java - Stack Overflow

    Oct 31, 2010 · The Java String class provides the .compareTo () method in order to lexicographically compare Strings. It is used like this "apple".compareTo ("banana"). The return of this method is an int …

  6. How do I write a compareTo method which compares objects?

    The compareTo () method on string will return a negative number for a string in alphabetical order before, and a positive number for one in alphabetical order after. Now, you just need to do the same …

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

    Sep 20, 2010 · return this.getName().compareTo(i.getName()); That should do what you want. Usually when implementing the interface, you will just combine the results of using other members of the …

  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. CompareTo() and compare() methods of comparator and comparable

    CompareTo () is used to define the 'natural order' of the objects and creates an int to determine which object is 'greater' than the other and implements Comparable.

  10. string - c# CompareTo () Method - Stack Overflow

    Jun 13, 2021 · The String.CompareTo method compares this instance with a specified object or String and returns an integer that indicates whether this instance precedes. if the return value is Less than …