Interview Question Q. If we have Employee List and in the List have Id, name ,salary then ,I want Salary is greater than 20000 by using Java8 Feature.

 Interview Question

Q. If we have Employee List and in the List have Id, name ,salary  then ,I want Salary is greater than 20000 by using Java8 Feature

Ans :- 

Test.java
package p1;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class Test {

public static void main(String[] args) {
List<Employee> list= new ArrayList<>();
list.add(new Employee(1, "Asha", 70000));
list.add(new Employee(2,"Poorinima",15000));
list.add(new Employee(3,"Neeta",5000));
List<Employee> list1=list.stream().filter(i->i.getSalary()>20000).collect(Collectors.toList());
// System.out.println(list1);
for(Employee e:list1) {
System.out.println("Emp Salary:"+e.getSalary());
}

}

}


package tcs;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class Test {

public static void main(String[] args) {
List<Employee> list= new ArrayList<>();
list.add(new Employee(1, "Asha", 70000));
list.add(new Employee(2,"Poorinima",15000));
list.add(new Employee(3,"Neeta",5000));
List<Employee> list1=list.stream().filter(i->i.getSalary()>20000).collect(Collectors.toList());
// System.out.println(list1);
for(Employee e:list1) {
System.out.println("Emp Salary:"+e.getSalary());
}

}

}


***********************************************************************************
package p2;

public class Employee {

private int id;
private String name;
private int salary;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
public Employee(int id, String name, int salary) {
super();
this.id = id;
this.name = name;
this.salary = salary;
}

}

*****************************************************************************

Comments

Popular posts from this blog

How to create React project using command prompt?

How to achieve abstraction?

Interview Question? How to find square of each element in this Array {2,4,5,6,8} using map ?