Select object from ARRAYLIST WITHOUT LOOP - ANDROID

筅森魡賤 提交于 2019-12-02 05:21:56

The Guava library is much more popular than lambdaj, and does allow you to avoid for, while loops by using preficates and filter methods.

If you want to select an element that matches a criteria (or elementS that will match), use the Java 8 filter function. (no need to use other libraries anymore).

Do it as:

List<Foo> listOfFoo = ...
Stream<Foo> matchingFoo = listOfFoo.stream().filter(t -> t.propertyOrMethod == 'criteria');

If you can use xpresso, you can write:

list<Sale> sortedSales = x.list(x.sorted(sales, x.invoke("getCost")));

(I am the author of xpresso)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!