Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
146 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...