title: How to sort listOfItem based on condition in Kotlin
body: <p>This is my given code</p>
  <pre><code>var type1 listOf&lt;Type&gt; = 0 size;
  var type2 listOf&lt;Type&gt; = {&quot;Ait 45&quot;,&quot;Ait 46&quot;}
  var type3 listOf&lt;Type&gt; = {&quot;Ait 47&quot;}
  var type4 listOf&lt;Type&gt; = 0
  var type5 listOf&lt;Type&gt; = {&quot;Ait 58&quot;,&quot;Ait 59&quot;}
  </code></pre>
  <p>Using below code i am sorting it</p>
  <pre><code>val data = ArrayList&lt;Product&gt;()
          data.add(Product(it=1,type1))
          data.add(Product(it=2,type2))
          data.add(Product(it=3,type3))
          data.add(Product(it=4,type3))
          data.add(Product(it=5,type4))
  
  data.sortedBy { it.type.get(0).value}
  </code></pre>
  <p>i am trying to sort based on type value but i am getting ArrayIndexoutBound exception because type1  and type4 having   empty or null so i want to  sort if such type of item should come at last  based on inserted order please help me how to apply condition to check if type  is empty or null i dont want sort those item simply i can keep at end of list .</p>