Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 826
User_87 Avatar asked Dec 01 '25 09:12

User_87


1 Answers

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.

like image 100
T. Neidhart Avatar answered Dec 03 '25 22:12

T. Neidhart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!