Forum

Number Of Page View:100,000+/Months
LOGIN |New User

Reply

How to compare two strings ?
There are two ways to compare the two strings in java:
  * using the == operator,
  * using the equals() method.

For Example:

String s1=new String("Hello!");
String s2=new String("Hello!");

if(s1==s2) 
System.out.println("Equal using == operator.");
elseif (s1.equals(s2))
System.out.println("Equal using equals method.");
else
System.out.println("Not Equal.");

Posted By: Name:Rajesh Kr URL: How to compare two strings ?