Java print output array and collection __java

Source: Internet
Author: User
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 ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.