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..
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)
来源:https://stackoverflow.com/questions/19198014/select-object-from-arraylist-without-loop-android