Select object from ARRAYLIST WITHOUT LOOP - ANDROID

后端 未结 3 1202
眼角桃花
眼角桃花 2021-01-24 22:31

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

相关标签:
3条回答
  • 2021-01-24 23:07

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

    0 讨论(0)
  • 2021-01-24 23:07

    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)

    0 讨论(0)
  • 2021-01-24 23:14

    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');
    
    0 讨论(0)
提交回复
热议问题