gIrL
gIrL

Reputation: 139

customised comparator in not working

I am using Comparator to sort my ListView, but it doesn't work.

My code:

Collections.sort(orgi, new Comparator<Loc>() {

                @Override
                public int compare(Loc lhs, Loc rhs) {

                    if( lhs.getDist() < rhs.getDist() )
                         return 1;
                      else
                         return 0;
                }
            });

Can anyone suggest a solution?

Upvotes: 0

Views: 176

Answers (1)

M-Wajeeh
M-Wajeeh

Reputation: 17284

Try this:

Collections.sort(orgi, new Comparator<Loc>() {

            @Override
            public int compare(Loc lhs, Loc rhs) {
                if(lhs.getDist() < rhs.getDist()){
                     return -1;
                 } else if(lhs.getDist() > rhs.getDist()){
                     return 1;
                 } else {
                     return 0;
                 }
            }
        });

Upvotes: 3

Related Questions