Javaでlistとmap変換するサンプルコード

1.List<V>をMap<K,V>へ変換
List<Item> list;
Map<Key,Item> map = new HashMap<Key,Item>();
for (Item i : list) map.put(i.getKey(),i);

2.Map<K,V>をList<V>へ変換
Map<String, String> m = new HashMap<String, String>();
m.put(“welcome", “programe");
m.put(“tm", “8");
m.put(“its", “Element");
List<String> list = new ArrayList<String>(m.keySet());
List<String> list = new ArrayList<String>(m.values());

Java

Posted by arkgame