How do you compare two strings? any predefined method for
this?

Answers were Sorted based on User's Feedback



How do you compare two strings? any predefined method for this?..

Answer / niranjanravi

equals() method

Is This Answer Correct ?    8 Yes 2 No

How do you compare two strings? any predefined method for this?..

Answer / guest

equals() method

Is This Answer Correct ?    6 Yes 2 No

How do you compare two strings? any predefined method for this?..

Answer / 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

More Core Java Interview Questions

Is java type safe?

0 Answers  


What differences exist between iterator and listiterator?

0 Answers  


When do you call copy constructor?

0 Answers   Tavant Technologies, Virtusa,


What is unmodifiable list in java?

0 Answers  


Is vector synchronized in java?

0 Answers  


Describe the term diamond problem.

0 Answers  


How many methods does cloneable interface contains?

6 Answers  


What is cloneable interface?

8 Answers  


what is run time polymorphism

4 Answers  


how to handled exceptions & erros in ejb?

1 Answers   Satyam,


What restrictions are placed on method overloading?

0 Answers  


How to split a string in java?

0 Answers  


Categories