[英]using loop instead of stream (java9)
I wonder how to change into for or while loop by using same format 我想知道如何通过使用相同的格式更改为for或while循环
public List<String> noZ(List<String> strings) {
return strings.stream().filter(x -> !x.contains("z")).collect(Collectors.toList());
}
This is what I did so far, but I'm not getting the results yet: 这是我到目前为止所做的,但尚未得到结果:
for (int i = 0; i < string.stream().size(); i++) {
string x;
if (x.contains("z")) {
String.valueOf(strings.stream().filter);
}
}
There are a few reasonable ways to rewrite this. 有几种合理的方法可以重写它。 One way: 单程:
public List<String> noZ(List<String> strings) {
List<String> out = new ArrayList<>();
for (String s : strings) {
if (!s.contains("z")) {
out.add(s);
}
}
return out;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.