How to get min/max from ArrayList based on its object attribute values?
I think you're looking for minBy
and maxBy
:
val minObject: CustomObject? = arrayList.minBy { it.floatVal1 }
val maxObject: CustomObject? = arrayList.maxBy { it.floatVal1 }
val maxObj: Object? = arrayList.maxByOrNull { it.floatVal1 }
val minObj: Object? = arrayList.minByOrNull { it.floatVal2 }
maxBy, minBy are deprecated since Kotlin 1.4