Search code examples
javaarrayshashmap

How to do an array of hashmaps?


This is what I tried to do, but it gives me a warning:

HashMap<String, String>[] responseArray = new HashMap[games.size()];

Type safety: The expression of type HashMap[ ] needs unchecked conversion to conform to HashMap[ ]


Solution

  • What gives? It works. Just ignore it:

    @SuppressWarnings("unchecked")
    

    No, you cannot parameterize it. I'd however rather use a List<Map<K, V>> instead.

    List<Map<String, String>> listOfMaps = new ArrayList<Map<String, String>>();
    

    To learn more about collections and maps, have a look at this tutorial.