I have List<City> cities. I need to convert cities into a map Map<String, Integer>, where the value (Integer) has to be auto-generated.
I tried this, but it seems not allowed to use counter like that because of atomic error. Ho to solve this task?
public Map<String, Integer> convertListToMap(List<City> cities) {
Integer counter=0;
return cities.stream().forEach(elem->tollFreeVehicles.put(elem.getName(), counter++));
}