我需要通过包含的任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