2016-03-10 135 views
1

我是java 8 lamdas的新手。我需要帮助下面的集合聚合和排序列表。 我有对象的ArrayList中具有列表使用lambdas的Java集合集合

[ 
[parentName1,parentkey1, child1Name1, childKey1], 
[parentName1,parentkey1, child1Name2, childKey2], 
[parentName3,parentkey3, child1Name3, childKey3], 
[parentName3,parentkey3, child1Name4, childKey4], 
[parentName5,parentkey5, child1Name5, childKey5], 
[parentName5,parentkey5, child1Name6, childKey6] 
] 

我会使用Java 8个Lambda表达式中排序列表喜欢聚集上方集合。

List(Parent(parentName1,parentkey1, List( Child(child1Name1,childKey1),Child(child1Name2, childKey2) ), 
    Parent(parentName3,parentkey3, List( Child(child1Name3,childKey3),Child(child1Name4, childKey4) ), 
    Parent(parentName5,parentkey5, List( Child(child1Name5,childKey5),Child(child1Name5, childKey6) ) 
    ); 

任何帮助将不胜感激。

回答

0

我不明白使用哪种排序标准来排序列表,但这里是通用示例,但稍作修改即可适用于您的案例。

employeeList.stream() 
      .sorted((e1, e2) -> Integer.compare(e1.getEmployeeNumber(), e2.getEmployeeNumber())) 
      .forEach(e -> System.out.println(e)); 

上述例子表明examplyee对象可以排序基于员工数量,但你可以改变,以适应你的情况的逻辑。