Home > Back-end >  Turn a Java List <Long> map <Long, Long>?
Turn a Java List <Long> map <Long, Long>?

Time:11-24

List How to convert map format

CodePudding user response:

The
refer to the original poster cqhweb response:
List How to convert map The format

The effect of what would you like to do? Asked a little abrupt

CodePudding user response:

First you have to understand, deposit a Lst information, save two Map, the Map is the key (key) value (value) to exist,
List and Map is stored in the object, so we put the List object inside a data as the key, the object as the value in the Map,
Such as: deposit in this two kinds of data in the List: student id and the name of the students, (id, name), id as the key, students object as the value in the Map,

CodePudding user response:

refer to the second floor Vicali response:
above all you should understand, deposit a Lst information, save two Map, the Map is the key (key) value (value) to exist,
List and Map is stored in the object, so we put the List object inside a data as the key, the object as the value in the Map,
Such as: deposit in this two kinds of data in the List: student id and the name of the students, (id, name), id as the key, the students object as the value in the Map,

The same thought turn Map List:
HashMap deposit in this two kinds of data: student id and the name of the students, (id, name), we need to get the HashMap and List into each other, can the id, name encapsulated in the object, deposited in the Map collections

CodePudding user response:

1. The for loop
2. The characteristics of jdk8
Map Maps=userList. Stream (). Collect (Collectors. ToMap (User: : getId, Function, identity (), (key1, key2) - & gt; Key2));

  • Related