package com.jdk.api.test;
public class Strings {
public static void main(String[] args)
{
String a1 = null;
// 事实证明证明使用stringbuilder 比使用string 连加操作快很多
StringBuilder sb = new StringBuilder();
long start = System.currentTimeMillis();
for(int i = 0; i< 100000;i++){
a1=a1+"al";
}
long end = System.currentTimeMillis();
System.out.println("--:"+(end-start));
start = System.currentTimeMillis();
for(int i = 0; i< 100000;i++){
sb = sb.append("sb");
}
end = System.currentTimeMillis();
System.out.println("--:"+(end-start));
}
/*
* --:39394
--:13
*/
}
public class Strings {
public static void main(String[] args)
{
String a1 = null;
// 事实证明证明使用stringbuilder 比使用string 连加操作快很多
StringBuilder sb = new StringBuilder();
long start = System.currentTimeMillis();
for(int i = 0; i< 100000;i++){
a1=a1+"al";
}
long end = System.currentTimeMillis();
System.out.println("--:"+(end-start));
start = System.currentTimeMillis();
for(int i = 0; i< 100000;i++){
sb = sb.append("sb");
}
end = System.currentTimeMillis();
System.out.println("--:"+(end-start));
}
/*
* --:39394
--:13
*/
}