Computer Science, asked by komalpatil8780, 1 year ago

what is difference in equals() and compareTo() in java

Answers

Answered by rkburman72
0

Equals command check the equality of 2 strings. But compare to command compares the 2 strings.

Answered by Anonymous
2

Hey mate!!

equals() checks if two objects are the same or not and returns a boolean. compareTo() (from interface Comparable) returns an integer. It checks which of the two objects is "less than", "equal to" or "greater than" the other. ... Note that equals() doesn't define the ordering between objects, which compareTo() does.

hope this helps you.

mark as brainliest


Similar questions