how to compare strings java

Java
System.out.println("hey".equals("hey")); //prints true

/*
	always use .equals() instead of ==,
    because == does the compare the string content but
    loosely where the string is stored in.
*/class scratch{
    public static void main(String[] args) {
        String str1 = "Nyello";
        String str2 = "Hello";
        String str3 = "Hello";

        System.out.println( str1.equals(str2) ); //prints false
        System.out.println( str2.equals(str3) ); //prints true
    }
}// Java program to Compare two strings 
// lexicographically 
public class GFG { 
    public static void main(String args[]) 
    { 
        String string1 = new String("Geeksforgeeks"); 
        String string2 = new String("Practice"); 
        String string3 = new String("Geeks"); 
        String string4 = new String("Geeks"); 
        String string5 = new String("geeks"); 
  
        // Comparing for String 1 != String 2 
        System.out.println("Comparing " + string1 + " and " + string2 
                           + " : " + string1.equals(string2)); 
  
        // Comparing for String 3 = String 4 
        System.out.println("Comparing " + string3 + " and " + string4 
                           + " : " + string3.equals(string4)); 
  
        // Comparing for String 4 != String 5 
        System.out.println("Comparing " + string4 + " and " + string5 
                           + " : " + string4.equals(string5)); 
  
        // Comparing for String 1 != String 4 
        System.out.println("Comparing " + string1 + " and " + string4 
                           + " : " + string1.equals(string4)); 
    } 
} 
if (aName.equals(anotherName))
        { 
            System.out.println(aName + " equals " + anotherName);
        }
        else 
            { 
                System.out.println(aName + " does not equal " +anotherName );
                           
            }
Source

Also in Java: