Select object from ARRAYLIST WITHOUT LOOP - ANDROID

ぐ巨炮叔叔 提交于 2019-12-31 04:12:28

问题


I am looking for a library which can select object from ArrayList like SQL "where" command.

I have huge arraylists (between 2000 and 20000) in my project and i don't want to write for,while loops every time..

I found lambdaj and it is for Java.

I tried to use lambdaj inside my Android project but i couldn't do it.

For example when i write List<Sale> sortedSales = sort(sales, on(Sale.class).getCost());
this example code in my project, eclipse couldn't see "sort", "on" commands..

Is there another library like lambdaj or can anyone tell me how can i use lambdaj in my android project ?

Thanks..


回答1:


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




回答2:


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');



回答3:


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)



来源:https://stackoverflow.com/questions/19198014/select-object-from-arraylist-without-loop-android

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