I have
LinkedHashMap<String, List<String>> hMap;
I want to get List<String>
by position not on key.
I don't want to use iterate.
Is there any other way to get Value based on index ?
Method 1(Using keys array): You can convert all the keys of LinkedHashMap to a set using Keyset method and then convert the set to an array by using toArray method now using array index access the key and get the value from LinkedHashMap.
Arrays store items in an ordered collection and are accessed using an index number (which is an integer). HashMap stores items as key/value pairs. Values can be accessed by indexes, known as keys, of a user-defined type.
LinkedHashMap. containsKey() method is used to check whether a particular key is being mapped into the LinkedHashMap or not. It takes the key element as a parameter and returns True if that element is mapped in the map.
You can't get the value of the Map
based on index, Map
s just don't work that way. A workaround would be to create a new list from your values and get the value based on index.
LinkedHashMap<String, List<String>> hMap; List<List<String>> l = new ArrayList<List<String>>(hMap.values()); l.get(0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With