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.\");elseSystem.out.println(\"Not Equal.\");