Java 7 中的 Java 流

java streams in Java 7(Java 7 中的 Java 流)

本文介绍了Java 7 中的 Java 流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题可能过于宽泛,答案可能很简单,但我必须问.

My question may be too broad and probably the answer is a simple NO, but I have to ask.

是否有 (Java 8) 流的任何等效实现* 在 Java 7 中?

Is there any equivalent implementation of (Java 8) streams* in Java 7?

我熟悉 (Java 8) 流,但我的项目要求是使用 Java 7.

I am familiar with (Java 8) streams but my project requirement is to use Java 7.

*不要与 inputStream 和 outputStream.

推荐答案

在官方API中,没有.

In the official API, no.

没有更多针对 Java 7 的公开更新.如果您是客户,您可能仍会获得较小的更新,但这不会(或非常非常不可能)用于向后移植 Stream API.

There is no more public updates for Java 7. If you're a customer, you might still get minor updates, but this not (or very very very unlikely) for back-porting the Stream API.

稍加挖掘,您可能会查看 StreamSupport.我从未测试过它,但显然它的目标是将 Stream API 向后移植到 Java 6/7,如果你想将它与 lambda 表达式结合起来,还有 retrolambda.

With a bit of digging you may look at StreamSupport. I've never tested it but apparently its goal is to backport the Stream API to Java 6/7 and if you want to combine it with lambda expressions there's also retrolambda.

Functional Java 可能很有趣.它与 Stream API 的意图并不完全相同,但如果您的目标是过滤/映射/等.一个列表/数组,它可能适合您的需求.对于示例:

Functional Java can be interesting. It's not exactly the same intent as the Stream API but if your goal is to filter/map/etc. a list/array it might suits your needs. For example:

final List<Integer> b = list(1, 2, 3).map(add.f(-1));
listShow(intShow).println(b); // [0, 1, 2]

最后,您可以查看 Scala 的 Stream API.由于 Scala 也在 JVM 上运行,因此您可以混合您的代码.也许这不是您想要的,但如果需要,值得一试.

Finally you can look into the Scala's Stream API. As Scala runs also on the JVM, you can mix your code. Maybe it's not exactly what you are looking for but it's worth a try if needed.

这篇关于Java 7 中的 Java 流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Java 7 中的 Java 流

基础教程推荐