创建字符串的较佳途径 你可以按照以下方式创建字符串对象: 1. String s1 = "hello"; long endTime = (); ("Time taken for creation of String literals : " + (endTime - startTime) + " milli seconds" ); // create String objects using ‘new‘ keyword long startTime1 = (); for(int i=0;i<50000;i++){ String s3 = new String("hello"); String s4 = new String("hello"); } long endTime1 = (); ("Time taken for creation of String objects : " + (endTime1 - startTime1)+" milli seconds"); } } 这段代码的输出: Time taken for creation of String literals : 0 milli seconds Time taken for creation of String objects : 170 milli seconds