I have an array, I add values in this array, I send them to a method in another class that puts the values of this array in a string only and I add this single string in an ArrayList, but when I go to show it, it shows only several nulls ".
Main class:
class Principal {
public static void main(String[] args) {
Scanner entrada = new Scanner(System.in);
Logica chamar = new Logica(valores);
String[][] valores = new String[3][2];
ArrayList colecao = new ArrayList();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
if (j == 0) {
System.out.println("Insira um nome.");
} else {
System.out.println("Insira um número.");
} valores[i][j] = entrada.next();
}
} colecao.add(chamar);
for (Object resolucao:colecao) {
System.out.println(resolucao.toString());
}
}
}
Logical class:
class Logica {
String valores;
public Logica(String[][] valores) {
valores = new String[3][2];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
this.valores = valores[i][j] + "\n";
}
}
}
public String toString() {
return valores;
}
}
What's wrong?