dataList.stream().collect(Collectors.groupingBy(AmelioratePlanExpertReview::getApplyId)) 如何返回LinkedList
时间: 2025-09-03 18:21:01 AIGC 浏览: 5
`dataList.stream().collect(Collectors.groupingBy(AmelioratePlanExpertReview::getApplyId))` 的结果是一个 `Map`,要将这个 `Map` 的键或值转换为 `LinkedList` 类型,可以采用以下方式:
#### 转换 `Map` 的键为 `LinkedList`
```java
import java.util.*;
import java.util.stream.Collectors;
class AmelioratePlanExpertReview {
private String applyId;
public AmelioratePlanExpertReview(String applyId) {
this.applyId = applyId;
}
public String getApplyId() {
return applyId;
}
}
public class Main {
public static void main(String[] args) {
List<AmelioratePlanExpertReview> dataList = Arrays.asList(
new AmelioratePlanExpertReview("1"),
new AmelioratePlanExpertReview("2"),
new AmelioratePlanExpertReview("1")
);
Map<String, List<AmelioratePlanExpertReview>> groupedMap = dataList.stream()
.collect(Collectors.groupingBy(AmelioratePlanExpertReview::getApplyId));
LinkedList<String> keyList = new LinkedList<>(groupedMap.keySet());
System.out.println(keyList);
}
}
```
#### 转换 `Map` 的值为 `LinkedList`
```java
import java.util.*;
import java.util.stream.Collectors;
class AmelioratePlanExpertReview {
private String applyId;
public AmelioratePlanExpertReview(String applyId) {
this.applyId = applyId;
}
public String getApplyId() {
return applyId;
}
}
public class Main {
public static void main(String[] args) {
List<AmelioratePlanExpertReview> dataList = Arrays.asList(
new AmelioratePlanExpertReview("1"),
new AmelioratePlanExpertReview("2"),
new AmelioratePlanExpertReview("1")
);
Map<String, List<AmelioratePlanExpertReview>> groupedMap = dataList.stream()
.collect(Collectors.groupingBy(AmelioratePlanExpertReview::getApplyId));
LinkedList<List<AmelioratePlanExpertReview>> valueList = new LinkedList<>(groupedMap.values());
System.out.println(valueList);
}
}
```
阅读全文
相关推荐
















