Top "Compareto" questions

The CompareTo method is found in the .NET Framework and Java and imposes the natural ordering of a class.

compareTo() vs. equals()

When testing for equality of String's in Java I have always used equals() because to me this seems to be …

java string equals compareto
How to simplify a null-safe compareTo() implementation?

I'm implementing compareTo() method for a simple class such as this (to be able to use Collections.sort() and other …

java refactoring comparison null compareto
How do I write a compareTo method which compares objects?

I am learning about arrays, and basically I have an array that collects a last name, first name, and score. …

java comparable compareto
compareTo with primitives -> Integer / int

Is it better to write int primitive1 = 3, primitive2 = 4; Integer a = new Integer(primitive1); Integer b = new Integer(primitive2); int compare = …

java performance compareto
BigDecimal equals() versus compareTo()

Consider the simple test class: import java.math.BigDecimal; /** * @author The Elite Gentleman * */ public class Main { /** * @param args */ public static …

java equals bigdecimal compareto
Comparing two strings in java character by character

I am beginner in java, I am trying to compare two strings in java char by char and find how …

java string char compareto
How to use the Comparable CompareTo on Strings in Java

I can use it to sort by emp id but I'm not sure if it is possible to compare strings. …

java comparable compareto
Why is compareTo on an Enum final in Java?

An enum in Java implements the Comparable interface. It would have been nice to override Comparable's compareTo method, but here …

java enums comparable compareto
Implementing custom compareTo

@Override public int compareTo(Object t) { if(t instanceof Student) { Student s = (Student)t; return (this.name.compareTo(s.name)); } …

java compareto
Java, how to use compareTo to sort an Arraylist

Im trying to figure out how to sort an ArrayList using comparable, my code looks like this: public class playerComparsion{ …

java comparable compareto