How to display the values of an ArrayList separately?

-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 that's where the problem is, how to display the right item in the right column?

    
asked by anonymous 21.04.2014 / 01:08

1 answer

1
  

This response was for an earlier version that the question already had.

The println should already break the lines, try the variant below, if it is a platform difference problem:

ArrayList exemplo = new Arraylist();
for (Object resolucao: exemplo) {
   System.out.println(resolucao);
}

Based on a comment you , you can split a string this way if your source is not an array:

Exemplo = original.split("\n");

for (Object resolucao: exemplo) {
   System.out.println(resolucao + "\r\n");
}

Regarding line breaks:

To know the line break of the platform in use, Java has

String newLine = System.getProperty("line.separator");

Or from Java 7,

String newLine = System.lineSeparator();
    
21.04.2014 / 01:54