public class Notes {
private int id;
private String tagName;
private long tagId;
public Notes(int id, String tagName, long tagId) {
Id = id;
this.tagName = tagName;
this.tagId = tagId;
}
}
public class TestNotes {
public static void main(String[] args) {
List<Notes> noteLst = new ArrayList<>();
noteLst.add(new Notes(1, "note1", 11));
noteLst.add(new Notes(2, "note2", 22));
noteLst.add(new Notes(3, "note3", 33));
noteLst.add(new Notes(4, "note4", 44));
noteLst.add(new Notes(5, "note5", 55));
noteLst.add(new Notes(6, "note4", 66));
Map<String, Long> notesRecords = noteLst.stream().collect(
Collectors.toMap(Notes::getTagName, Notes::getTagId,
(oldValue, newValue) -> oldValue
)
);
System.out.println("Notes : " + notesRecords);
}
}
Notes : {note1=11, note2=22, note3=33, note4=44, note5=55}
Notes : {note1=11, note2=22, note3=33, note4=66, note5=55}