int的最大值String是用数组来实现的吗,当然就使数组的最大元素数了

解决方案 »

  1.   

    64k
    超过64k会报错:Exception in thread "main" java.lang.ClassFormatError: ttt (Illegal constant pool type)
      

  2.   

    我用下面这个程序测试了一下,得到的结果是:17033470
    不知道在别人的机器上运行会不会得到别的结果?public class ttt {
    public static void main (String[] args) {
    StringBuffer sb = new StringBuffer(17033470);
    String s = null;
    try {
    for (int i = 0; i < Integer.MAX_VALUE; i++) {
    sb.append(i%10);
    }
    } catch (java.lang.OutOfMemoryError ex) {
    System.out.println("FULL");
    }
    s = sb.toString();
    System.out.println(s.length());
    s = s + "3";
    System.out.println(s.length());
    }
    }