Java equals() method

    equals() method

    This equals() method in Java will allow you to compare the two strings on their content basis. If any of the characters of both the strings will not be matched, then it will return false else, it will return true. This method will override the Object class’s method of equals().

    Syntax-

    public boolean equals(Object anotherObject)  

    Example-

    public class Simple{  
    
        public static void main(String[] args) {      
    
          String s1="java";  
    
          String s2="java";  
    
          String s3="JAVA";  
    
          System.out.println(s1.equals(s2));
    
          System.out.println(s1.equals(s3));
        }
    }  

    Output-