I'm new to Java (and not too comfortable with strong typing) and I have a method that takes in a HashMap. A key in this hashmap contains a key, which has a hashmap for value, which also points to a hashmap, etc, until we reach a string:y
HashMap1->HashMap2->HashMap3->HashMap4->String
I am trying to access it as follows:
HashMap1
.get("aKey")
.get("anotherKey")
.get("yetAnotherKey")
.get("MyString");
But then I get an error,
Object does not have a method "get(String)
Here is the method, simplified:
public HashMap<String, HashMap> getMyString(Map<String, HashMap> hashMap1) {
String myString = hashMap1
.get("aKey")
.get("anotherKey")
.get("yetAnotherKey")
.get("MyString");
// do something with myString.
return hashMap1;
}
How would someone properly define the method and the parameters to access nested elements easily?
Thank you,