我正在尝试对包含自定义对象的arraylist
进行排序。我想根据对象内的属性对arraylist
进行排序。
以下是我的代码:
List<Object[]> search = qry1.getResultList();
以下是我的输出:
"searchresults" = ArrayList<E>
elementData=Object[33]
[0] = Object[10]
[0] = "Dog"
[1] = "Animal"
[2] = "Carnivorous"
[1] = Object[10]
[0] = "Lion"
[1] = "Animal"
[2] = "Carnivorous"
[2] = Object[10]
[0] = "Cow"
[1] = "Animal"
[2] = "Herbivorous"
[3] = Object[10]
[0] = "Buffalo"
[1] = "Animal"
[2] = "Herbivorous"
现在我想根据动物名称(布法罗,狗,狮子)对结果进行排序
我尝试使用java 8功能,但没有工作。也尝试使用comparator
,但没有工作:
search.stream().sorted(comp1, comp2);
请指导。