There is a list with several elements. The elements in it has two criteria: id
and value
. I want to sort them by value
and get first three elements, then put the elements which id != 1
to the end of the list.
for example:
class Test {
int id;
int value;
public Test(int id, int value) {
this.id = id;
this.value = value;
}
}
Test a = new Test(1,4);
Test b = new Test(2,3);
Test c = new Test(1,1);
Test d = new Test(2,5);
origin list: a,b,c,d
sort by value
and get first three elements:
c,b,a
put the elements which id != 1
to the end of the list:
c,a,b
how to implement it in a efficient and elegant way?