0

Search for a value in a List

I have a collection of lists, that i initialized has HashMap <Integer, String [ ] > In String [ 1] i have a name, and i want to check in all the list i have, on that HashMap, wich ones have the same value in String [1] and save the Int associated with that List. Hope i wasn't very confusing.

10th Nov 2016, 6:02 PM
Carolina Xavier
Carolina Xavier - avatar
1 ответ
+ 4
i assume you want to iterate on the HashMap for a given name parameter and save all the key values which have that name appear on the string array at index 1 you could try this method implementation which returns an array list of the integers with the matching name in the index 1 array of the string: public ArrayList<Integer> getNameKeys(String name, HashMap<Integer, String[]> map){ ArrayList<Integer> nameKeys = new ArrayList<Integer>(); for(Integer key: map.keySet()){ if(map.get(key)[1] == name) nameKeys.add(key); } return nameKeys; }
10th Nov 2016, 6:56 PM
Burey
Burey - avatar