English

Differentiate between compareTo() and equals(). - Computer Applications

Advertisements
Advertisements

Question

Differentiate between compareTo() and equals().

Distinguish Between

Solution

S. No. compareTo() equals()
1. This function analyses whether a string is equal to, more significant than, or smaller than another string. This function in the String class checks if two strings are identical. (The equals() function handles upper and lower case characters differently).
2. It produces an integer-type value. (The function returns 0 if both strings are equal, a negative number if the first string is smaller, and a positive value if the first string is larger). It returns a boolean value (true or false).
shaalaa.com
  Is there an error in this question or solution?
Chapter 4: String Handling - EXERCISES [Page 289]

APPEARS IN

Avichal Computer Applications [English] Class 10 ICSE
Chapter 4 String Handling
EXERCISES | Q VI. 2. | Page 289
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×