title: How to get min/max from ArrayList based on its object attribute values?
body: <p>What I want to achieve is to get min/max attribute value of object from <code>ArrayList&lt;Object&gt;</code>. For example if <code>Object</code> has attribute <code>weight</code>(float), I want heaviest object from the list.</p>
  
  <p>I've tried to implement Comparable to get max/min value but this returns same value for min and same for max for some reason. (I don't know if it works with floats)</p>
  
  <pre><code>    val maxVal: Float = arrayList.max().floatVal1
      val minVal: Float = arrayList.min().floatVal1
  
      data class CustomObject(var val1: String, var floatVal1: Float , var floatVal2: Float?, var floatVal3: Float?, var floatVal4: Float?): Comparable&lt;CustomObject&gt;{
          override fun compareTo(other: CustomObject) = (floatVal1 - other.floatVal1).toInt()
      }
  </code></pre>
  
  <p>That specific question from duplicate post does not show me how to get max/min value based on Float. That's the problem. If I want to modify Comparator it accepts only Int. And i cant use that stream feature because my app is for API 23+ not 24+</p>