The interchange between array list map in Java

Source: Internet
Author: User

The transformation of the relationship between the three, a picture clearly presented.


Code on:

One of the Maputils is Apache's collection package.

Package util;

Import java.util.ArrayList;
Import Java.util.Arrays;
Import Java.util.HashMap;
Import java.util.List;
Import Java.util.Map;

Import Org.apache.commons.collections.MapUtils;

public class Convert {public
	static void Main (string[] args) {
		//1. Array converted to List,map
		string[] arr = {"123", "456" , "789", "123"};
		list<string> list =  arrays.aslist (arr);
		Array to Map, one-dimensional array, the odd number is key, even for value, odd elements, the last drop
		//. Two-D arrays as two one-dimensional arrays
		map = Maputils.putall (new HashMap (), ARR);
		
		string[][] ss = {{"A", "B", "E"},{"C", "D", "F"}};
		Maputils.debugprint (SYSTEM.OUT,ARR,MAP);
		Maputils.putall (map, arr);
		Maputils.debugprint (SYSTEM.OUT,ARR,MAP);
		Maputils.putall (map, ss);		
		Maputils.verboseprint (System.out,arr,maputils.invertmap (map));
		
		List converts to arr
		list<string> ls = new arraylist<string> ();
		Ls.add ("WCh");
		Ls.add ("name");
		String[] as = (string[]) Ls.toarray ();
		
	}
}


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.