1
linq4jを使用しています。私は1つのプロパティでソートするだけで、複数のプロパティで並べ替えることにします。もし私が使用できる他の方法よりもlinq4jでサポートされていません。以下は、私のコードスニペット、オブジェクトの複数のプロパティをソートする方法 - linq4j
import java.util.Arrays;
import java.util.List;
import net.hydromatic.linq4j.Linq4j;
import net.hydromatic.linq4j.function.*;
public class Linq4jExample {
public static class Employee {
public final int empno;
public final String name;
public final int deptno;
public Employee(int empno, String name, int deptno) {
this.empno = empno;
this.name = name;
this.deptno = deptno;
}
public String toString() {
return "Employee(empno: " + empno +",name: " + name + ", deptno:" + deptno + ")";
}
}
public static final Employee[] emps = {
new Employee(100, "Fred", 10),
new Employee(110, "Bill", 30),
new Employee(120, "Bill", 10),
new Employee(120, "Eric", 12),
new Employee(130, "Janet", 13),
};
public static final Function1<Employee, Integer> EMP_DEPTNO_SELECTOR =
new Function1<Employee, Integer>() {
public Integer apply(Employee employee) {
return employee.deptno;
}
};
public static void main(String[] args) {
List<Employee> filter=Linq4j.asEnumerable(Arrays.asList(emps))
.orderBy(new Function1<Employee,String>()
{
public String apply(Employee arg0)
{
return arg0.name;
}
}).toList();
}
}
潜在的なユースケースは、部門番号でソートすることができ、その後、名前
私のプロジェクトの使用JDK7を、これを行うことができます。 – flower
私の答えを確認 – GauravJ
それは私が欲しいものは機能ではありません。名前で注文と同じです。私はあなたの答えを試しています。 – flower