gpt4 book ai didi

java - 为什么我无法在 java Stream 的代码中使用收集器?

转载 作者:行者123 更新时间:2023-12-05 08:20:24 25 4
gpt4 key购买 nike

<分区>

import static java.util.stream.Collectors.*;
import java.util.*;
import java.lang.*;
//import java.util.Collections;
public class HelloWorld{

public static void main(String []args){
System.out.println("Hello World");
List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");
List<String> filtered = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.toList());
}
}

输出

/tmp/java_tdo3eB/HelloWorld.java:10: error: cannot find symbol
List<String> filtered = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.toList());
^
symbol: variable Collectors
location: class HelloWorld
1 error

所以我想知道为什么我无法使用 Collectors,因为我也导入了那个类

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com