Emre Koç
Emre Koç

Reputation: 1381

Select object from ARRAYLIST WITHOUT LOOP - ANDROID

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..

Upvotes: 1

Views: 1568

Answers (3)

aburkov
aburkov

Reputation: 13

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)

Upvotes: 0

Breno Inojosa
Breno Inojosa

Reputation: 602

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

Upvotes: 0

lbalazscs
lbalazscs

Reputation: 17784

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

Upvotes: 1

Related Questions