Packagecom.xxx.xxx; Public classDemo7 {/*** String Generator * J2SE variable string sequence String-builder class *@paramargs*/ Public Static voidMain (string[] args) {String str= "";//Create an empty string//to define the start time of an operation on a string LongStartTime =System.currenttimemillis (); for(inti = 0; i < 1000; i++) {//executes 1000 times with A for loopstr = str + i;//Loop Append string } LongEndTime = System.currenttimemillis ();//define the time after the string operation LongTime = Endtime-starttime;//calculate the time to execute on a stringSystem.out.println ("Str Consumption time:" +Time ); //Create a stringStringBuilder Builder =NewStringBuilder (""); StartTime= System.currenttimemillis ();//define the time before an operation is executed for(intj = 0; J < 100000; J + +) {builder.append (j); //Loop Append string//System.out.println (Builder.append (j));} endTime=System.currenttimemillis (); time= EndTime-StartTime; System.out.println ("StringBuilder Consumption time:" +Time ); }}
6. String Generator String-builder