Java - getting max value from an arraylist of objects?

后端 未结 5 954
北恋
北恋 2020-11-27 08:14

Is there an easy way to get the max value from one field of an object in an arraylist of objects?

For example, out of the following object, I was hoping to get the h

5条回答
  •  攒了一身酷
    2020-11-27 08:27

    You should iterate over the list comparing/finding the max value O(N). If you need to do this often replace the list with a PriorityQueue O(1) to find the max.

提交回复
热议问题