String与StringBuilder性能比对

//String与StringBuilder性能比对
package seday01;
/**
* String修改字符串带来的性能开销
* @author xingsir
*
*/
public class StringDemo2 {
public static void main(String[] args) {
String str = "a";
for(int i=0;i<10000000;i++) {
str = str+"a";
}
System.out.println("执行完毕!");
}
}


//=============================================================================

//package seday01;
///**
// * StringBuilder修改字符串的性能
// * @author xingsir
// *
// */
//public class StringDemo3 {
// public static void main(String[] args) {
// StringBuilder builder = new StringBuilder("a");
// for(int i=0;i<10000000;i++) {
// builder.append("a");
// }
// System.out.println("执行完毕!");
// }
//}

猜你喜欢

转载自www.cnblogs.com/xingsir/p/11978045.html