public class Empty { // Demonstrate that the empty substring is not interned/canonical public static void main ( String [] args ) { String s = "a very long string"; // create an empty substring String e1 = s.substring( 0, 0 ); // make sure the empty string is canonical String e2 = ( e1.length() == 0 ) ? "" : e1; out.println( e1 == "" ); // always prints false out.println( e2 == "" ); // always prints true } }