Computer Applications
Which one of the given statements is true for the following statement? string1.compareTo(string2)
- if string1 > string2 the result will be a negative integer i.e. < 0.
- if string1 > string2 the result will be a positive integer i.e. > 0.
- if string1 > string2 the result will be 0.
- None of the above
Java String Handling
2 Likes
Answer
if string1 > string2 the result will be a positive integer i.e. > 0.
Reason — The compareTo() method compares two strings lexicographically, and returns a value based on the following logic:
- if string1 > string2 the result will be a positive integer, i.e., result > 0
- if string1 < string2 the result will be a negative integer, i.e., result < 0
- if string1 = string2 the result will be 0, i.e., result = 0
Answered By
1 Like
Related Questions
The indexOf() method returns the position of the …………… .
- first occurrence of the specified character
- last occurrence of the specified character
- null character
- '\n' character
The return type of the equals() method is …………… .
- int
- char
- boolean
- void
Which one of the given statements is true for the following statement? string1.compareTo(string2)
- if string1 > string2 the result will be a positive integer i.e. > 0.
- if string1 < string2 the result will be a negative integer i.e. < 0.
- if string1 = string2 the result will be 0 i.e. = 0.
- all of these
The valueOf() method returns the …………… .
- string representation of the argument
- int representation of the argument
- boolean representation of the argument
- character representation of the argument