How to find the max element from an array list of objects?

前端 未结 5 658
小鲜肉
小鲜肉 2021-01-18 13:55

Collections.max(arraylist) doesn\'t work, and a regular for loop won\'t work either.

What I have is:

ArrayList

        
5条回答
  •  悲&欢浪女
    2021-01-18 14:40

    here is the simple method that return a max value from arraylist

    public static object GetMaxValue(ArrayList arrayList)

    {

     ArrayList sortArrayList= arrayList;
    
     sortArrayList.Sort();
    
     sortArrayList.Reverse();
    
     return sortArrayList[0];
    

    }

提交回复
热议问题