class TestStringModifications {

    public static void main(String[] args) {
    
        String s1 = "Hello ";        // create obj ref to "Hello "
        
        // the following operations return NEW string objects
        // the original string referenced by s1 is NEVER MODIFIED
        
        System.out.println("s1.concat(\"World\") \t\t" + s1.concat("World"));
        System.out.println("s1 after concat(): \t\t" + s1 );
        
        System.out.println("\ns1.replace('H','J'): \t\t" + s1.replace('H','J'));
        System.out.println("s1 after replace(): \t\t" + s1);
        
        System.out.println("\ns1.substring(2): \t\t" + s1.substring(2));
        System.out.println("s1 after substring(): \t\t" + s1);
        
        System.out.println("\ns1.toLowerCase(): \t\t" + s1.toLowerCase());
        System.out.println("s1 after toLowerCase(): \t" + s1);    
        
        System.out.println("\ns1.toUpperCase(): \t\t" + s1.toUpperCase());
        System.out.println("s1 after toUpperCase(): \t" + s1);    
        
        System.out.println("\ns1.length(): \t\t\t" + s1.length());
        System.out.println("s1.trim().length(): \t\t" + s1.trim().length());
        System.out.println("s1.length() after trim(): \t" + s1.length());    

        // comparing strings which are created using modification method
        if(" String ".trim() == "String")
            System.out.println("Result of trim() & ==: Equal");
        else
            System.out.println("Result of trim() & ==: Not Equal");

        if("string".toUpperCase() == "STRING")            
            System.out.println("Result of toUpperCase() & ==: Equal");
        else
            System.out.println("Result of toUpperCase() & ==: Not Equal");
            
        // to test the resulting values use equals()
        if( (" String ".trim()).equals("String"))
            System.out.println("Result of trim() & equals(): Equal");
        else
            System.out.println("Result of trim() & equals(): Not Equal");
                    

    }

}
