Based on tquadrat’s answer (in Java):
public static class User{
boolean isFalse;
int value;
public User(boolean b, int v){
this.isFalse = b;
this.value = v;
}
public String toString() { return "User("+this.isFalse+", "+this.value+")"; }
}
public static void main(String[] args) {
User[] users = {new User(true, 5), new User(true, 1),new User(false, 7),
new User(true, 10), new User(false, 3)};
ArrayList<User[]> output = new ArrayList<>();
int start = 0;
int end = 0;
while( end < users.length )
{
if( users[end].isFalse == false)
{
output.add( Arrays.copyOfRange( users, start, end ));
start = end + 1;
}
++end;
}
if( start < end ) output.add( Arrays.copyOfRange( users, start, end ));
for (User[] arr: output){
System.out.println(Arrays.toString(arr));
}
}
Giving output:
[User(true, 5), User(true, 1)]
[User(true, 10)]
1
solved How to split an array of objects in java or Kotlin?