I want a strange
There is an array of objects. Each object has a unique id field. I want to convert this array to HashMap with keys equal to this id
Yes, I know how to do this through a cycle. But maybe there is a more elegant way, streams, magic castes, etc. which i just don't know about?
class Accident{ public int id; .... } Accidents[] accArray = getAccidentsByRetrofitAndGson(); Map accidents<Integer,Accident> = new HashMap(); // Вот вместо этого? for(Accident acc:accidents){ accidents.put(acc.id, acc); }