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 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
Answer
all of these
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
Related Questions
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 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
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
Output of the following statement is …………… .
System.out.println("SUNDAY".substring(3));
- NDA
- DAY
- SUN
- N