Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
144 views
in Technique[技术] by (71.8m points)

stream() method does not work in android

How can I convert this statement from classic java to android

Collection<Integer> p1;   
int sum = p1.stream().mapToInt(Integer::intValue).sum();

I integrate Java 8 and lambda to my android application, but it still does not work. The method stream() does not found in android.

Can you help me?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use the streamsupport library which backports the stream API to Java 6/7 which can be used for Android development, supported on all devices.

Afaik, this library fully backports the original implementation present in Java 8 and makes it available in a separate package (prefix java8.). The added default methods on the Collection interface (e.g. #stream(), #forEach()) are available from separate utility classes, e.g. Iterables or StreamSupport.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...