How do you compare two strings? any predefined method for
this?
Answer Posted / sumann
You can compare the values of 2 Strings by following
methods of String class:-
Eg:- String a="abc"; String b="abc";
1> .equals() method it will return a boolean value.
eg:- if(a.equals(b)) will return true.
2> .compareTo() method.If the two java strings are exactly
the same, the compareTo method will return a value of 0
(zero).
eg:- if (a.compareTo(b) == 0){
// this line will print
System.out.println("a and b strings are the same.")
}
| Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
How do you compare arrays in java?
What is the difference between iterator and list iterator?
Define an abstract class with reference to java.
What is null mean in java?
Which is better list or arraylist in java?
What is the advantage of OOP in java?
What are the two types of java?
What is the vector class in java programming?
Does unicode support all languages?
Is treeset sorted in java?
What is autoboxing and unboxing?
In a container there are 5 components. I want to display all the component names, how will you do that?
Write an algorithm program in java for the following question.. In a VLSI design techniques,they used rectangles to design circuits. EVery rectangle is to be placed according to x,y coordinates. Check whether or not two rectangles overlap each other. Here overlapping of rectangles is acceptable, if 1) one rectangle intersect with other. 2) one rectangle fully covers other. The time of algorithm should not exceed o(n logn).
Can you make a constructor final in Java?
What is package private scope in java?