1

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

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Emre Koç
  • 1,343
  • 1
  • 25
  • 44
  • Why do you try to load data between 2k and 20k? From my exp. better to tell to SQL "from .. to" – Maxim Shoustin Oct 05 '13 at 12:58
  • Maxim is right. SQL is exactly for this purpose. What you could do with kludging arraylists would just waste memory and performance too compared to any SQL implementation... – ppeterka Oct 05 '13 at 13:02
  • I have to do this. I am already using SQL in my project. I am getting 20000 data from database for drawing. I am working with map and if user want to see every building in New York, i have to draw every building at New York and i have to put them into arraylist. – Emre Koç Oct 05 '13 at 13:05
  • 2
    Make sure you have `import static ch.lambdaj.Lambda.*;` in your source code file. – M-Wajeeh Oct 05 '13 at 13:09
  • Important Note : lambdaj is **not working** for Android !! – Emre Koç Oct 05 '13 at 16:56

3 Answers3

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.

lbalazscs
  • 17,474
  • 7
  • 42
  • 50
0

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');
Breno Inojosa
  • 602
  • 1
  • 10
  • 20
0

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)

aburkov
  • 13
  • 2
  • 5