2012-07-16 99 views
-3

如何在java中使用循環(或動態)創建多個地圖(集合)?使用循環創建多個地圖(集合)

List<Integer> temp = new ArrayList<Integer>(); 

for(int i=1; i<=10; i++) 
{ 

    Map<Integer, Map> temp.get(i) = new HashMap<Integer, Map>(); 
} 

考慮臨時有值 「一」, 「二」 ...... 「十」

請幫助..

+0

這是什麼語言?也許是Java? – 2012-07-16 13:15:26

+0

是...... Java ... – 2012-07-16 13:18:29

+0

'temp'不能具有值'「one」,「two」...「ten」'因爲它是'List '。你的意思是'1,2,...,10'? – dasblinkenlight 2012-07-16 13:18:34

回答

0

這將創建10個映射一個數組爲您提供:

List<Map> temp = new ArrayList<Map>(); 

for(int i=1; i<=10; i++) 
{ 

    temp.add(new HashMap<Integer, Map>()); 
} 
0

不知道我完全理解你。這是你想要的?

List<Map<Integer, Map> temp = new ArrayList<Map<Integer, Map>>(); 

for(int i=1; i<=10; i++) 
{ 
    Map<Integer, Map> map = new HashMap<Integer, Map>(); 
    temp.add(map); 
} 

//Get the maps as you please here, from the tmp list