package comnf147Package; import java.util.ArrayList; import java.util.List; public class String_Test { public static void main(String[] args) { long n = 1000000; long startTime=System.currentTimeMillis(); List<Thread> thread = new ArrayList(); { StringBuffer sb=new StringBuffer(); thread=new ArrayList<>(); for (int i = 0; i < n ; i++) { Thread t=new Thread(); thread.add(t); sb.append("."); } long endTime=System.currentTimeMillis(); System.out.println("Buffer"+(endTime - startTime)/1000.0+"ms"); } { StringBuilder sb=new StringBuilder(); thread=new ArrayList<>(); for (int i = 0; i < n ; i++) { Thread t=new Thread(); thread.add(t); sb.append("."); } long endTime=System.currentTimeMillis(); System.out.println("Builder"+(endTime - startTime)/1000.0+"ms"); } { String str; thread=new ArrayList<>(); for (int i = 0; i < n ; i++) { Thread t=new Thread(); thread.add(t); str=i+"."; } long endTime=System.currentTimeMillis(); System.out.println("String"+(endTime - startTime)/1000.0+"ms"); } } }