Java Print output arrays and collectionsIn Java, you can print out arrays and collections directly, without requiring us to write loops to print out the output. Arrays can be output through the arrays.tostring (int[]) function, and because collection classes such as the list set map implement the ToString () method, the output can be printed directly. For example, the following code
Import java.util.ArrayList;
Import Java.util.Arrays;
Import Java.util.LinkedHashMap;
Import java.util.List;
Import Java.util.Map;
The public class array and the printed output of the collection {
private static list<string> filllist (list<string> List) {
List.add (" Meihao ");
List.add ("Jason");
List.add ("Edison");
return list;
}
private static map<string,integer> Fillmap (map<string,integer> Map) {
map.put ("Undergraduatebegin" ,);
Map.put ("Postgraduatebegin");
Map.put ("Postgraduateend", num);
return map;
}
public static void Main (string[] args) {
//First print output array
int[] ages = {18,22,23,26};
Call Arrays.tostring (int[]) converts an array to a string printout
System.out.println (arrays.tostring (Ages));
##############################
System.out.println (filllist (new ArrayList));//Direct Output list
System.out.println (Fillmap (New Linkedhashmap ()))//Direct output Map
}
}
The output results are:
So later, through the console to print out the array and the collection object no longer need to consider using the loop, you can directly print the output ...