Question: java 8 lambda question: when I put this in eclipse, all these errors pop up. I am following along with a tutorial online. can someone

java 8 lambda question:

when I put this in eclipse, all these errors pop up. I am following along with a tutorial online. can someone help me figure this out?

package io.javabrains.unit1;

import java.util.Arrays; import java.util.Collections; import java.util.List;

import io.javabrains.common.Person;

public class Unit1ExerciseSolutionJava8 {

public static void main(String[] args) { List people = Arrays.asList( new Person("Charles", "Dickens", 60), new Person("Lewis", "Carroll", 42), new Person("Thomas", "Carlyle", 51), new Person("Charlotte", "Bronte", 45), new Person("Matthew", "Arnold", 39) );

// Step 1: Sort list by last name Collections.sort(people, (p1, p2) -> p1.getLastName().compareTo(p2.getLastName()));

// Step 2: Create a method that prints all elements in the list System.out.println("Printing all persons"); printConditionally(people, p -> true);

// Step 3: Create a method that prints all people that have last name beginning with C System.out.println("Printing all persons with last name beginning with C"); printConditionally(people, p -> p.getLastName().startsWith("C"));

System.out.println("Printing all persons with first name beginning with C");

printConditionally(people, p -> p.getFirstName().startsWith("C"));

}

private static void printConditionally(List people, Condition condition) { for (Person p : people) { if (condition.test(p)) { System.out.println(p); } } } }

Here is the Person class:

public class Person {

private String firstName; private String lastName; private int age;

public Person(String firstName, String lastName, int age) { super(); this.firstName = firstName; this.lastName = lastName; this.age = age; }

public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public int getAge() { return age; } public void setAge(int age) { this.age = age; }

@Override public String toString() { return "Person [firstName=" + firstName + ", lastName=" + lastName + ", age=" + age + "]"; }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!