Reputation: 360
How I can get sublist from?
Map<String, HashMap<String, String>>
I have tried:
Collections.list(Collections.enumeration(myMap.values())).subList(from,too)
UPD:
Method returns List<HashMap<String, String>>
only. But I need List<String, HashMap<String,String>>
Upvotes: 0
Views: 872
Reputation: 15690
You probably want to use Map.entrySet(), not Map.values(). It will provide a set of key-value pairs, which is what you want.
If you are expecting the entries to be in the order you inserted them with, use LinkedHashMap instead of HashMap.
Also, unimportantly, consider getting rid of the enumeration, and just use new ArrayList(myMap.entrySet())
.
Upvotes: 2
Reputation: 1661
If you are seeing NullPointerException, then Check if your "myMap" has properly initialized and have at least not empty.
If you are seeing IndexOutOfRangeException, then Two arguments "from" and "to" should be in the range of map size. from >= 0 to <= map's max size
Upvotes: 1