Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
JavaVsKotlin2
ArrayList<Student> students = new ArrayList<Student>() {{
add(new Student("John", 0));
add(new Student("Julia", 2));
add(new Student("Matt", 1));
add(new Student("Katie", 0));
add(new Student("Dan", 0));
}};
ArrayList<Student> firstList = new ArrayList<>();
ArrayList<Student> secondList = new ArrayList<>();
for (Student student: students) {
boolean isFirstFilled = firstList.size() >= 3;
boolean isSecondFilled = secondList.size() >= 2;
if (isFirstFilled && isSecondFilled) break;
int mark = student.getMark();
if (mark == 0 && !isFirstFilled) {
firstList.add(student);
} else if (mark == 1 && !isSecondFilled) {
secondList.add(student);
}
}
var students = listOf(
Student("John", 0),
Student("Julia", 2),
Student("Matt", 1),
Student("Katie", 0),
Student("Dan", 0)
)
var firstList = students.filter { it.mark == 0 }.take(3)
var secondList = students.filter { it.mark == 1 }.take(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment