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

How many types of threads are there in java?

0 Answers  


What is the original name of java?

0 Answers  


what is the JNDI?

3 Answers  


Are maps ordered java?

0 Answers  


Why chararray() is preferred over string to store the password?

0 Answers  






what is use of marker interface? give me good example?

2 Answers  


Give us a program to check for parenthesis matching using stack.

0 Answers   Genpact,


Differences between external iteration and internal iteration?

0 Answers  


How can you say HashMap is syncronized?

14 Answers   Arete, IBM,


Is java a prime method?

0 Answers  


Explain about the main() method in java?

0 Answers  


What is continuity of a function?

0 Answers  


Categories