-1
class Principal {
public static void main(String[] args) {
Scanner entrada = new Scanner(System.in);
ArrayList colecao = new ArrayList();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
System.out.println("Insira um nome.");
colecao.add(entrada.next());
}
} for (Object resolucao:colecao) {
String formato = "| %-15s | %-10s |%n";
System.out.format("+---------------+----------+%n");
System.out.printf("| Nome | Nome 2 |%n");
System.out.format("+---------------+----------+%n");
System.out.format(formato, resolucao, resolucao + "%n");
System.out.format("+---------------+----------+%n");
}
}
}
I need to display separately using a for-each and there’s the problem, how to display the right item in the right column?
Define "all together".
resolucaowill always be an object, you want to print a property of it?– bfavaretto
I want to print the values of Arraylist
exemplousing a for-each, e.g.: in the example index 0 has the string"lápis", in index 1 the string"caneta", when you print, you get"lápiscaneta", but I want to print separately,"lápis"and"caneta".– ptkato
Console output.
– ptkato
I guess I was wrong to explain, actually, I need to separate a string into two, ex.:
"lápiscaneta"which is at index 0 in"lápis", in index 0 and"caneta", in index 1. .– ptkato
That code is exactly what I’m doing, the only difference is that in the
this.valores += valores[i][j]: http://answall.com/questions/13488/arraylist-retornando-valores-nulos– ptkato
Sort this.values += values[i][j] for this.values += values[i][j] + ' n' Or create a separate array and use arrayseparada.add( values[i][j] )
– Bacco