I have a problem in JAVA when i'm trying to return a HashMap that I have added to a list of type: List<Object>
. I know I can use other type of lists, but I need to use List<Object>
List<Object> listOfObjects = new ArrayList<Object>();
HashMap<String, String> hashmap = new HashMap<String,String>();
hashmap.put("x", "foo");
hashmap.put("y", "bar");
listOfObjects.add(hashmap);
for (int i = 0; i < listOfObjects.size(); i++) {
System.out.println(listOfObjects.get(i));
}
I have added my hashmap to my listOfObject, but how do I get the HashMap from the listOfObject such that I can use the HashMap-commands. fx: hashmap.get("x) and it will return "foo".
Normally i thought i could just write: listOfObjects.get(0).get("x") and it would return "foo" but that does not work.
If anyone know another work around that's find but I just need to use a List.