belostoky
belostoky

Reputation: 974

How to implement Java 8 Stream API using Java 7 or older?

I was asked this question in a job interview (Microsoft).
methods to implement for example:
.stream(), .filter(), .map() , flatMap() , min() , count() , reduce() , groupBy()
etc

It's quite an open question but I think is an interesting one.

Thanks

Upvotes: 5

Views: 2817

Answers (3)

123-xyz
123-xyz

Reputation: 637

Here is a good example: Lightweight-Stream-API. It implements almost all stream APIs for Android/Java 7 by iterators.

Upvotes: 1

yegodm
yegodm

Reputation: 1044

I would not waste time creating those functions myself as it also implies quite rigorous testing. I would rather use Kotlin. It works with any Java starting from 6 and has all of these features (including lambdas) plus many others. Additionally it provides quite good compatibility with the core Java partially solving deficiencies of generics implementation.

Upvotes: -1

Oleg Ushakov
Oleg Ushakov

Reputation: 1555

One way to get an ability to use StreamAPI in your Java7 and Java6 projects add a streamsupport library https://github.com/streamsupport/streamsupport Streamsupport is a backport of the Java 8 java.util.function (functional interfaces) and java.util.stream (streams) API for users of Java 6 or 7

Upvotes: 3

Related Questions