I have a list of hashmap.
One field is an Integer, and the other one is a Boolean which will tell me if that item is selected or not.
The final purpose is to change the ArrayList, unselected the old one item which was selected, and marking the new one. I made this piece of code, but I wich to know if there is a better way to do it.
VisualizationBean visualizationBean = new VisualizationBean();
ArrayList<HashMap<Boolean, Integer>> resultsPerPage = visualizationBean.getResultsPerPage();
for (Iterator iterator = resultsPerPage.iterator(); iterator.hasNext();) {
HashMap<Boolean, Integer> hashMap = (HashMap<Boolean, Integer>) iterator.next();
if(hashMap.containsKey(true)){
int beforeSelected = hashMap.get("true");
hashMap.put(false, beforeSelected);
}
else{
if(hashMap.get(false) == number){
hashMap.put(true, number);
}
}
}
Thanks in advance
Please don’t use a List of Maps to do what you are doing.
Use
BitSet, it’s designed for this exact purpose. (Depending on your requirements you may need a list of BitSets, but never a List of Maps, especially not from Boolean to anything).Alternatively you could use a Map from Integer to Boolean (not from Boolean to Integer).