See which of your colleagues or former colleagues are already on Java Link: Check out the Contact Finder
News »Browse Articles » How to Compare Strings in Java
0
Vote Vote

How to Compare Strings in Java

Views 1 Views    Comments 0 Comments    Share Share    Posted by Balamurali 16-11-2010  
ackage com.javadb.examples;

public class Main {

public static void main(String[] args) {

String s1 = new String("abc");
String s2 = new String("abc");

if (s1 == s2) {
System.out.println("s1 == s2");
}

if (s1.equals(s2)) {
System.out.println("s1.equals(s2)");
}

if (s1.compareTo(s2) == 0) {
System.out.println("s1.compareTo(s2) == 0");
}
}
}
0
Vote  Vote
Enter your comment:
No Comments For This News

Search News

What's the News?

Post a link to something interesting from another site, or submit your own original writing for the Java community to read.

Most Popular News

Most Recent User Submitted News