How do you compare two strings? any predefined method for
this?
Answers were Sorted based on User's Feedback
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 |
How many types of threads are there in java?
What is the original name of java?
what is the JNDI?
Are maps ordered java?
Why chararray() is preferred over string to store the password?
what is use of marker interface? give me good example?
Give us a program to check for parenthesis matching using stack.
Differences between external iteration and internal iteration?
How can you say HashMap is syncronized?
Is java a prime method?
Explain about the main() method in java?
What is continuity of a function?