public class PerfAnal { public static void main( String[] args ) { //int loopCounter = Integer.MAX_VALUE; int loopCounter = 2000000; //constValue: //String.valueOf( 10 ): 5330 //new String( "" + 10): 1810 //"" + 10: 60 //variable ( i ): //String.valueOf( i ): 5930 //new String( "" + i ): 32730 //"" + i: 18780 String s; long start=System.currentTimeMillis(); for( int i = 1; i<loopCounter; i++ ) { s = "" + i; } long ende=System.currentTimeMillis(); System.out.println("Test1: "+(ende-start)); start=System.currentTimeMillis(); for( int i = 1; i < loopCounter; i++ ) { s=new String( "" + i ); } ende=System.currentTimeMillis(); System.out.println("Test2: "+(ende-start)); start=System.currentTimeMillis(); for( int i = 1; i < loopCounter; i++ ) { s=String.valueOf( i ); } ende=System.currentTimeMillis(); System.out.println("Test3: "+(ende-start)); System.out.println( ); }}