You are here: irt.org | FAQ | Java | Q4018 [ previous next ]
Two possiblities:
See the following example
// example of an incorrectly initialized array:
public class Test {
public static void main(String args[]) {
String sa[] = new String[5];
sa[0].charAt(0);
}
}
// example of a correctly initialized array:
public class Test {
public static void main(String args[]) {
String sa[] = new String[5];
for(int i = 0; i < 5; i++) {
sa[i] = new String();
}
sa[0].charAt(0);
}
}Of course now you'll get a "java/lang.StringIndexOutOfBoundsException" but that's because all of the Strings are empty ;-)