我需要通過包含的任String, ArrayList<Users>
或String, HashSet<Users>
對於給定的值的鍵/值的HashMap
進行搜索。我不確定如何編寫代碼來在java中執行此操作。搜索一個HashMap <字符串,ArrayList的<Users>>或HashMap中<字符串,HashSet的<Users>>
我宣佈..
private HashMap<String, ArrayList<Users>> cm = new HashMap<>();
我的方法需要被稱爲搜索看起來像這樣...
public void doSomething(User u, String product) {
}
所以我不能確定的是如何在方法內部的代碼會工作。
if (cm.containsKey(product) {
//This is where I'm unsure if I find the key on how to check if the ArrayList has a
particular user. And then if not how to add them.
}
你的代碼是不syntatically正確。您可以請在這裏發佈您的真實代碼請 – smk
此外,您的問題是模糊的。請告訴你已經嘗試了什麼。 – smk