Populando uma arry String apartir de um for - erro java.lang.ArrayIndexOutOfBoundsException: 1

Olá
Estou tentando popular um array de string e estou tendo o seguinte erro :

erro:
java.lang.ArrayIndexOutOfBoundsException: 1

For:

try {
String des2[]={""};
for(int i2 = 0; i2<10; i2++){
des2[i2] = “texto” + i2;
}
System.out.println(“total:” + des2.length);
} catch (Exception ex) {
ex.printStackTrace();
}

Alguem saberia me dizer porque?

Grato

Silva

Você tem de especificar o tamanho final de seu array de strings (arrays de strings não aumentam sozinhos de tamanho).

 try {
String des2[]= new String [10];
for(int i2 = 0; i2&lt10; i2++){
des2[i2] = &quot;texto&quot; + i2;
}
System.out.println(&quot;total:&quot; + des2.length);
} catch (Exception ex) {
ex.printStackTrace();
} 
String des2[]={""}; 

Com essa linha você está criando um array de Strings com tamanho igual a 1…

Uma solução alternativa sem necessitar o tamanho do array, é trabalhar com alguma implementação de lista e depois retornar os dados como array.

Até!