Java中的+会利用StringBuilder来实现,例如
public class Test1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
StringBuilder sb = new StringBuilder("0123456789");
StringBuilder sb1 = new StringBuilder();
for(int i = 0; i < 100; i++){
sb1.append("1");
}
System.out.println("length " + sb.length() + " Capacity " + sb.capacity());
//String str = null;
sb.append(sb1.toString());
System.out.println(sb.capacity() + " " +sb.toString());
}
}
用jad反编译为
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: Test1.java
import java.io.PrintStream;
public class Test1
{
public Test1()
{
}
public static void main(String args[])
{
StringBuilder sb = new StringBuilder("0123456789");
StringBuilder sb1 = new StringBuilder();
for(int i = 0; i < 100; i++)
sb1.append("1");
System.out.println((new StringBuilder("length ")).append(sb.length()).append(" Capacity ").append(sb.capacity()).toString());
sb.append(sb1.toString());
System.out.println((new StringBuilder(String.valueOf(sb.capacity()))).append(" ").append(sb.toString()).toString());
}
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/591258/viewspace-1134821/,如需转载,请注明出处,否则将追究法律责任。