No.. There is no max length for the size of an Array. Although you might run into an OutOfMemoryError
.
public static void main(String[] args) {
StringBuilder sb = new StringBuilder("");
for(int i=0;i<10000000000l;i++){
sb.append(i).append(" ");
}
System.out.println(sb.toString().split("\\s").length);
}
The above code might give OutOfMemoryError
on some machines (it did on mine. tried it with jdk 6)
public static void main(String[] args) {
StringBuilder sb = new StringBuilder("");
for(int i=0;i<10000;i++){
sb.append(i).append(" ");
}
System.out.println(sb.toString().split("\\s").length);
}
The above code works fine and prints 1000