DeveloperSection

Home / DeveloperSection / Forums / How to Sort hashSet by two conditions?

How to Sort hashSet by two conditions?

Anonymous User 1894 30-May-2015

I’m want to sorting a category bu name and place categories with ids: -1, 0 in begin

public class Category {
    Long id;
    String name;
 
    public Category(Long id, String name) {
        this.id=id;
        this.name=name;
    }   
}
 
Set<Categories> categories = new HashSet<>;
categories.add(new Category(2,'Kamlakar'))
categories.add(new Category(-1,'Pawan'))
categories.add(new Category(3,'Haider'))
categories.add(new Category(1,'Manoj'))
categories.add(new Category(0,'All'))

how to get such list

[{-1,' Pawan '}, {0,'All'}, {3,' Haider '}, {1,' Kamlakar '}, {2,'Historical'}]


Updated on 30-May-2015
I am a content writter !

Leave Answer


Please enter your answer.


1 Answers

Liked By