I have various ArrayList
s nested in one HashMap
.
How can I check if my array list nested in the hashmap exists?
public static HashMap<Integer, ArrayList<Integer>> transactionMap = new HashMap<Integer, ArrayList<Integer>>();
public static void initializeLists() {
transactionMap.put(7, new ArrayList<Integer> (Arrays.asList(1050, 1125)));
transactionMap.put(305, new ArrayList<Integer>(Arrays.asList(1125)));
transactionMap.put(1125, new ArrayList<Integer>(Arrays.asList(250, 252, 251)));
transactionMap.put(1050, new ArrayList<Integer>(Arrays.asList(251, 252)));
transactionMap.put(1124, new ArrayList<Integer>(Arrays.asList(250)));
transactionMap.put(1049, new ArrayList<Integer>(Arrays.asList(251, 252)));
}
This post here describes how to check directly in an Array
List
using #contains(Object)
, which does not fit for HashMap
.
This one is close but it would mean I would have to give a name to all my lists (and there could be many). I would like to avoid having to nest a map inside a map if possible unless needed. Does anyone have any points to the best solution?