简体   繁体   English

为什么我的JAVA项目中不能实现Streams功能?

[英]Why can't I Implement Streams functionality in my JAVA project?

I'm a beginner of JAVA programming. 我是JAVA编程的初学者。 Recently, I tried to use the map & filter functionality of Stream s like the following code shows. 最近,我尝试使用Streammapfilter功能,如以下代码所示。

    List<String> strList = Arrays.asList("abc", "", "bcd", "", "defg", "jk");
    long count = strList.stream().filter(x -> x.isEmpty()).count();
    System.out.printf("List %s has %d empty strings %n", strList, count);

However, the compiler always complains that I need to "Create local variable x". 但是,编译器总是抱怨我需要“创建局部变量x”。

Maybe I lose some basic steps that is too easy to find any related discussions on Google. 也许我失去了一些基本步骤,这些步骤太简单了,无法在Google上找到任何相关讨论。

My JAVA compiler version is J2SE 1.5, and I import java.util.stream.* to my file. 我的JAVA编译器版本是J2SE 1.5,我将java.util.stream。*导入到我的文件中。

Thanks! 谢谢!

Stream s and lambda expressions are Java 8 functionality. Stream s和lambda表达式是Java 8的功能。 Upgrade your compiler. 升级您的编译器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java 8 Streams - 为什么我不能对整数流求和? - Java 8 Streams - Why can't I sum a Stream of Integers? 如何使用流来实现与Java 8相同的功能 - How can i achieve the same functionality with Java 8 using streams 为什么我不能在Eclipse Maven项目中将类导入到我的java文件中? - Why can't I import a class into my java file in my Eclipse Maven Project? Java 8,如何使用流实现switch语句? - Java 8, how can I implement a switch statement using streams? 为什么不能在此VectorQueue实例上实现我的Vector方法? - Why can't I implement my Vector methods on this instance of VectorQueue? 为什么我不能在Java NatTable中用特定的CellEditor实现CellEditorMouseEventMatcher? - Why can't I implement a CellEditorMouseEventMatcher with a specific CellEditor in Java NatTable? 如何在我的活动中实现“不再显示”功能? - How can i implement the “do not show again” functionality on my activity? 为什么我不能从脚本执行Java项目? - Why can I not execute my java project from a script? 为什么我不能从Eclipse运行Spring项目? - Why can't I run my Spring project from eclipse? 为什么我不能在html上启动我的LibGDX项目? - Why can't I launch my LibGDX project on html?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM