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
// 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
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
Get step-by-step solutions from verified subject matter experts
