I have a nested collection in the form:
HashMap<String, HashMap<String, List<String>>> errorList;
Now I initialize it inline using double braces like this
errorList.put(tempName, new HashMap<String, List<String>>() {{
put("upl", new ArrayList<String>() {{ add("Y"); add("Upload Success"); }});
}});
This lies in a foreach loop with the value of tempName
changing in every iteration.
I did this because i couldn't use instances of List<String>
or HashMap<String,List<String>>
because every time i changed the value in that instance it is reflected in the collection it is nested in. So i am forced to create new instances with double brace initialization.
Thing is: I want to use a list object. Instead of
new ArrayList<String>() {{ add("Y"); add("Upload Success"); }}
I want to use a variable.
How can I do this?