I was wondering what the best way of printing a 2D array was. This is some code that I have and I was just wondering if this is good practice or not. Also correct me in any
@Ashika's answer works fantastically if you want (0,0) to be represented in the top, left corner, per normal CS convention. If however you would prefer to use normal mathematical convention and put (0,0) in the lower left hand corner, you could use this:
LinkedList printList = new LinkedList();
for (char[] row: array) {
printList.addFirst(Arrays.toString(row));;
}
while (!printList.isEmpty())
System.out.println(printList.removeFirst());
This used LIFO (Last In First Out) to reverse the order at print time.