public Map getCeny(){ ceny = new HashMap<>(); for(Spolka s : menager.getSpolki()){ Double wartosc = ceny.get(s.getSektor()); if(wartosc== null){ wartosc = 0.0; } ceny.put(s.getSektor(), wartosc + s.getOstatnie().getCena()); } return ceny; } into: public Map getCeny(){ return menager.getSpolki().stream().collect(Collectors. toMap(s -> s.getSektor(), s -> Optional.ofNullable(ceny.get(s.getSektor())).orElse(0.0) + s.getOstatnie().getCena())); }