I defined a hashmap as follows
HashMap<String, List<String>> hashmap = new HashMap<String, List<String>>(); I can get its content out by doing
Set<Map.Entry<String, List<String>>> keys = hashmap.entrySet(); for (Map.Entry<String,List<String>> entry : hashmap.entrySet()) { String key = entry.getKey(); List<String> thing = entry.getValue(); System.out.println (key); System.out.println (thing); } However, I would like to know:
- How could I retrieve its content to an ordinary string?
- Is it possible to access the strings on the fly? (without doing (1)) I mean, the same way you do
string[0], etc - Where is the length of the list stored?
hashmap.size()? Or do you want to have the length ofList<String>?HashMapis not ordered, so it makes no sense to access it by index.HashMap.entrySet().toArray();returns all Entries as an Array.