<> Conversion of List > and two-dimensional arrays

Source: Internet
Author: User
Tags arrays

/*

*list<map<object,object>> to two-dimensional arrays

* @param list

* @param the number of keys in Keylength-map

* @return

/


public static object[] [] Listtoarray (list<map<string,object>> list,int keylenght)

{

Object [] array=new object[list.size ()][keylenght]

for (int i=0;i<list.size (); i++)

{

Array[i]=list.get (i). VALUES (). ToArray ();

}

return array;

}



Map<string,object> conversion to a two-dimensional array

Map<string,object> map=new hashmap<string,object> ();

Map.put ("1", "a");

Map.put ("2", "B");

Map.put ("3", "C");

Object[] [] array=new object[map.size ()][2];

Object [] Keys=map.keyset (). ToArray ();

Object [] values=map.values (). ToArray ();

Or

/**

* string[][] array=new string[map2.size ()][2];
* String [] keys= map2.keyset (). ToArray (New String[map2.size ());
* String [] values=map1.values (). ToArray (new string[2]);

*/

for (int i=0;i<array.length;i++)

{

Array[i][0]=keys[i];

Array[i][0]=values[i];

}


for (int i=0;i<array.length;i++)

{for (int i=0;j<array[i].length;j++)

{

System.out.println (Array[i][j]);

}

}


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.