![](/img/trans.png)
[英]How to insert the same value for multiple keys of an HashMap using Java Streams
[英]How to view the common Values between multiple keys in Same HashMap in java?
HashMap<Integer,ArrayList<String>> = new HashMap<Integer,ArrayList<String>>();
ArrayList<constructor> frndList = new ArrayList<constructor> ();
在單個哈希圖中,我將使用整數值作為鍵,對於該鍵,我將使用list添加多個值
現在我的問題是鍵1具有兩個值,鍵3中具有相同的值,那么我必須查看嗎?
您必須手動在HashMap內部循環
dupl = null;
for(ek:map.keys()){
if(ek.get(ek).contains(my_value)){
dupl = ek.get(ek)
break;
}
}
如果dupl不為null,則鍵ek中有一個值
System.out.println("Enter first key");
int f=scan.nextInt();
System.out.println("Enter second key");
int s=scan.nextInt();
ArrayList<String> t1=new ArrayList<String>();
ArrayList<String> t2=new ArrayList<String>();
ArrayList<String> mf=new ArrayList<String>();
t1.addAll(map.get(f));
t2.addAll(map.get(s));
for(String temp1:t1)
{
if(t2.contains(temp1))
{
mf.add(temp1);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.