Yawar
Yawar

Reputation: 1943

OrderBy in android custom object list

I have a list of my own class object in android class.

I want to do two things with that list.

First I want to Apply order by like this I used to do with C# code.

myList.orderby(x => x.energyLevel);

Secondly I want to fetch some data from that list. Like this

myList.where(x=>x.gender=="male");

How to do this in android?

Upvotes: 0

Views: 122

Answers (1)

Arun C
Arun C

Reputation: 9035

orderby using ArrayList in android

  Collections.sort(myList, new Comparator<MyListObj>(){
  public int compare(MyListObj obj1, MyListObj obj2) {
    return obj1.x.compareToIgnoreCase(obj2.x);
  }
});

Upvotes: 1

Related Questions