String comparision in Java

String comparision method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.

Source code :

public class StringCompareequl{
   public static void main(String []args){
      String s1 = "tutorialspoint";
      String s2 = "tutorialspoint";
      String s3 = new String ("Tutorials Point");

Output :


Notes :

String s3 creates unnecessary String objects. But instead it should be written like this: String s3 = "tutorialspoint";

Algorithm :

  1. Create two strings namely s1, s2,s3.
  2. Checking the string are equal or not.

Output :


Comments :