como eu trabalho com arrays ?
eu andei fazendo uns testes mais nao obtive sucesso…
eu usei a busca do forum mais nao achei nada que fosse o que eu procuro…
[quote] public static void main(String[] args){
String[] e;
e[0] = "teste";
e[1] = "teste2";
e[2] = "teste3";
System.out.print(e[0]);
System.out.print(e[1]);
System.out.print(e[2]);
}[/quote]
alguem help?
abracos
ps: agora em quotes e sem swings
Qual eh a sua duvida mais especificamente?
Rafael
cd1
Abril 7, 2005, 12:07am
#3
olah!
vc precisa inicializar um array antes d usa-lo, assim como todo objeto em java:
public static void main(String[] args){
String[] e;
e = new String[3]; // Faltava isso: inicialize com o tamanho máximo q vc vai precisar
e[0] = “teste”;
e[1] = “teste2”;
e[2] = “teste3”;
System.out.print(e[0]);
System.out.print(e[1]);
System.out.print(e[2]);
}
[]'s!!
Rafael Steil, eu queria saber como usar um array !
cd1, era exatamente isso, obrigado !
novamente obrigado,
abracos
kina
Abril 7, 2005, 9:07am
#5
Você também pode fazer deste outro modo.
public static void main(String[] args){
String[] e;
e = new String[]{"teste","teste2","teste3"};
System.out.print(e[0]);
System.out.print(e[1]);
System.out.print(e[2]);
}
Assim tambem funciona:
String[] s = { "a", "b", "c", "d", "e" };
Rafael