Skip to content
Advertisement

How to split an array of objects in java or Kotlin?

I have already asked one question about this here but, that answers about only strings. I could not edit that as there a couple of answers there already.


Now, I get it how to split it with a space as given in that post. But, how can I split it with objects of custom class like this:

JavaScript

Now, I want to split on places where isAdult is false. For example I have this array:

JavaScript

Now, on splitting of isAdult to being false, it will be like this:

JavaScript

So, how can I achieve this in java or Kotlin

Advertisement

Answer

Based on tquadrat’s answer (in Java):

JavaScript

Giving output:

JavaScript
Advertisement