Created
March 25, 2017 03:32
-
-
Save stepango/470148f4d987584ee0431ab479f3039a to your computer and use it in GitHub Desktop.
JavaVsKotlin2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Вот за это я и люблю Лotlin. Коротко - ясно!