有關list集合轉換爲map集合

Map<Long,A> map = list.stream().collect(Collectors.toMap(A::getId,Function.identity(),(key1,key2)->key1),HashMap::new); 這個總體方法, 1,list的stream方法, 2.stream的coolect(Collectors)方法 3.Collector的tomap方法, 4,tomap方法中的參數:AllocateLogistics::getItemId這個參數是List的實體類As中的getId方法的返回值做爲key,而Function.identity()表明着類的自己來做爲value。也能夠用類中的某個屬性來做爲value。獲取方法和key相同。(key1,key2)->key1)而這句話的意思是,若是key值重複,取原來的值。HashMap::new是指定生成map的類型。ide

相關文章
相關標籤/搜索