I am trying to create a simple HashMap , which will have a String as a key , and for each key there's an ArrayList of Objects .
The problem with the solution I came up with is at the end of the loop , I get only one value (Object ) in the ArrayList ...
I tried using the MultiValueMap in Apache Commons but my IDE protests , it says it is deprecated
//filter products by supplier
for(String nume:SuppliersNames){
ArrayList<Order.Product> gol = new ArrayList<>();
SuppliersMap.put(nume,gol);
//we make a copy of the products collection so we can iterate it and filter elements by supplier
ArrayList<Orders.Order.Product> interm = new ArrayList<Orders.Order.Product>(products);
Iterator<Orders.Order.Product> iter = interm.iterator();
while (iter.hasNext()){
Orders.Order.Product curent = iter.next();
if(curent.getSupplier()== nume){
SuppliersMap.get(nume).add(curent);
}
}
}
Aucun commentaire:
Enregistrer un commentaire