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

What is bom encoding?

0 Answers  


What are the two categories of data types in the java programming language?

0 Answers  


What are access modifiers?

1 Answers   Infosys,


Name the components that are termed to be Heavy-weight component but available in Light-weight components?

0 Answers  


1) There are 10 different threads in runnable state. Each having priority 1 to 10. How does the CPU schedules or executes these threads?

2 Answers   RBS,






I have 100 records in a table with two rows. I need to display 10 records per page like Google Search. I need only the Logic(Pagination) in Pure Java. No JSP and all..Thanks in Advance...

2 Answers   Cybernet,


how to print the below in java? * * * * * * * * *

2 Answers  


Explain static nested classes ?

0 Answers  


How to optimize the javac output?

0 Answers  


What is prefix of a string?

0 Answers  


WHAT IS MARKER INTERFACE,AND NO METHODS IS NOT THERE ON THAT INTERFACE THEN WHY WE USED IN JAVA?

3 Answers   L&T,


How will you reverse a singly-link list?

0 Answers   Akamai Technologies,


Categories