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
Write a code to create a trigger to call a stored procedure
What are the types of methodology?
Is final static java?
What is the difference between numeric and integer?
What is the difference between an array and an array list?
Why hashcode is used in java?
What kind of variables can a class consist?
When will we use them?
What is the statements?
What is the most important feature of java? What is an interface?
What are different data structures in java?
Differentiate between a constructor and a method? Can we mark constructors final?
Should you use singleton pattern?
What access modifiers can be used for methods?
Explain about version control?