So, I\'m making a site about WWI as a school assignment, and I want this to appear in every document:
<
Different Ways to Print Arrays in Java:
Simple Way
List list = new ArrayList();
list.add("One");
list.add("Two");
list.add("Three");
list.add("Four");
// Print the list in console
System.out.println(list);
Output: [One, Two, Three, Four]
Using toString()
String[] array = new String[] { "One", "Two", "Three", "Four" };
System.out.println(Arrays.toString(array));
Output: [One, Two, Three, Four]
Printing Array of Arrays
String[] arr1 = new String[] { "Fifth", "Sixth" };
String[] arr2 = new String[] { "Seventh", "Eight" };
String[][] arrayOfArray = new String[][] { arr1, arr2 };
System.out.println(arrayOfArray);
System.out.println(Arrays.toString(arrayOfArray));
System.out.println(Arrays.deepToString(arrayOfArray));
Output: [[Ljava.lang.String;@1ad086a [[Ljava.lang.String;@10385c1, [Ljava.lang.String;@42719c] [[Fifth, Sixth], [Seventh, Eighth]]
Resource: Access An Array