Difficulty: Beginner
Estimated Time: 10 minutes

// This is your Editor pane. Write your Java here and // use the command line to execute commands //Write a program using lambda expression and collections sort to sort a list of employee //objects with the employee name in ascending order. Define Employee class with parameters ID, Name, Age. import java.util.*; public class App{ public static void main(String args[]){ List lst = new ArrayList(); lst.add(new Employee(2,12,"Sima")); lst.add(new Employee(1,11,"Tima")); lst.add(new Employee(3,13,"Mima")); lst.add(new Employee(4,14,"Rima")); lst.add(new Employee(5,15,"Lima")); Collections.sort(lst,(Employee o1, Employee o2)->o1.getName().compareTo(o2.getName())); lst.forEach(e->System.out.println(e)); }

static class Employee{
    Employee(){}
    Employee(int id, int age, String name){
      this.id=id; this.age=age; this.name=name;
    }
  
    private int id,age;
    private String name;
  
    public int getId(){return id;}
    public String getName(){return name;}
    public int getAge(){return age;}
  
    public void setId(int id){this.id=id;}
    public void setName(String name){this.name=name;}
    public void setAge(int age){this.age=age;}
  
    public String toString(){
      return "ID:"+id+", Name:"+name+", Age:"+age+"";
    }
  }
  

}

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Lambda Expression Handson 1

javac App.java

App