0
我需要一個HashMap一些東西,它看起來像哈希映射2個值Java
Map<String, int,ArrayList<String>> table = new HashMap<String, int,ArrayList<String>>();
但HashMap中只接受一個映射值。
我試着用一些包裝類,它看起來像
class Wrapper {
int id;
ArrayList<String> list = new ArrayList<String>();
//Here get and set methods
}
然後我的HashMap的樣子
Map<String, Wrapper> table = new HashMap<String, Wrapper>();
我需要什麼來實現這樣的:
當我指定int值到我的HaspMap那麼我應該能夠檢索該int值的ArrayList。
我該怎麼做?
如果我把它正確的,那麼你可以使用地圖 >>。 –
2015-03-31 04:23:47
聽起來像Wrapper應該包含第一個字符串和int,並將其用作鍵。一定要覆蓋equals和hashCode! – yshavit 2015-03-31 04:24:25