Skip to content

Commit

Permalink
feat: Add example filter out null students whose age is greater than …
Browse files Browse the repository at this point in the history
…18 from the list
  • Loading branch information
VishwajeetVT committed Dec 4, 2024
1 parent 4fe56d8 commit e2cc5d1
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public static void main(String[] args) {
stringsWithNull.add("Kotlin");
stringsWithNull.add(null);
System.out.println(filterNullValues(stringsWithNull));

List<Student> students = List.of(new Student("V", 25), new Student("R", 15), new Student("T",19));
filterStudents(students).forEach(s -> System.out.print(s.getName()+" "));
}

public static List<Integer> evenNumbers(List<Integer> list) {
Expand All @@ -40,4 +43,29 @@ public static List<String> filterNullValues(List<String> list) {
.filter(Objects::nonNull)
.toList();
}

// Filter out student whose age greater than 18.
public static List<Student> filterStudents(List<Student> students) {
return students.stream()
.filter(student -> student.getAge() > 18)
.toList();
}
}

class Student {
String name;
int age;

public Student(String name, int age) {
this.name = name;
this.age = age;
}

public String getName() {
return name;
}

public int getAge() {
return age;
}
}

0 comments on commit e2cc5d1

Please sign in to comment.