map<Integer,List>转String[]怎样转?
2个回答
展开全部
/**
* @author belen.liu
* @param map
* @return
* JDK version: 1.6.0
*/
private static Map<Integer,String[]> convertMap(Map<Integer,List> map){
if(map == null){
return null;
}
Map<Integer,String[]> returnMap = new HashMap();
for(Iterator it = map.entrySet().iterator();it.hasNext();){
Map.Entry entry = (Map.Entry)it.next();
List<String> list = (List)entry.getValue();
String[] strs = (String[])list.toArray(new String[]{});
returnMap.put(new Integer(entry.getKey()+""), strs);
}
return returnMap;
}
// Test
/**
* @author belen
* @param args
*/
public static void main(String[] args) {
Map<Integer,List> map = new HashMap();
List list = new ArrayList();
list.add("hello");
list.add("你好");
map.put(1, list);
Map<Integer,String[]> rMap = convertMap(map);
for(Iterator it = rMap.entrySet().iterator();it.hasNext();){
Map.Entry entry = (Map.Entry)it.next();
String[] aa = (String[])entry.getValue();
System.out.println(aa[0]);
System.out.println(aa[1]);
}
}
* @author belen.liu
* @param map
* @return
* JDK version: 1.6.0
*/
private static Map<Integer,String[]> convertMap(Map<Integer,List> map){
if(map == null){
return null;
}
Map<Integer,String[]> returnMap = new HashMap();
for(Iterator it = map.entrySet().iterator();it.hasNext();){
Map.Entry entry = (Map.Entry)it.next();
List<String> list = (List)entry.getValue();
String[] strs = (String[])list.toArray(new String[]{});
returnMap.put(new Integer(entry.getKey()+""), strs);
}
return returnMap;
}
// Test
/**
* @author belen
* @param args
*/
public static void main(String[] args) {
Map<Integer,List> map = new HashMap();
List list = new ArrayList();
list.add("hello");
list.add("你好");
map.put(1, list);
Map<Integer,String[]> rMap = convertMap(map);
for(Iterator it = rMap.entrySet().iterator();it.hasNext();){
Map.Entry entry = (Map.Entry)it.next();
String[] aa = (String[])entry.getValue();
System.out.println(aa[0]);
System.out.println(aa[1]);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询