如何在没有pojo类的java中对具有自定义对象的ArrayList进行排序?

时间:2016-11-07 13:53:39

标签: java sorting arraylist collections

我正在尝试对包含自定义对象的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);

请指导。

0 个答案:

没有答案