Short Employee using there salary

 

   Here we are going to use a short  Employee list according to their Age.  

   So  we  have two classes here 

           1. EmployeeMax.class 

          2. FindMaxSalaryEmployee.class

 

  Here   I  am sorting Employees according to their salary we will find max salary later.  


 import java.util.Comparator;

import java.util.List;

import java.util.stream.Collectors;

import java.util.ArrayList;


public class FindMaxSalaryEmployee {


 

    

           

    public static void main(String[] args) {

  

    List<EmployeeMax> EmployeeMaxs = new  ArrayList<>(); 

EmployeeMaxs.add(new EmployeeMax("Monu",32 ,77000));

      EmployeeMaxs.add(new EmployeeMax("Sonu",30,50000));  

      EmployeeMaxs.add(new EmployeeMax("Eklu",35,40000)); 

      EmployeeMaxs.add(new EmployeeMax("Viru",28, 30000)); 

      EmployeeMaxs.add(new EmployeeMax("Pri",20, 35000)); 

        

/*List<EmployeeMax> sortedList = EmployeeMaxs.stream()

.sorted((o1, o2) -> o1.getAge() - o2.getAge())

.collect(Collectors.toList());*/

  

List<EmployeeMax> sortedList = EmployeeMaxs.stream()

.sorted(Comparator.comparingInt(EmployeeMax::getSalary)).collect(Collectors.toList());

        sortedList.forEach(EmployeeMax -> System.out.println("Employee salary "

                + EmployeeMax.getSalary()));

        

        

        

      //sortedList.forEach(System.out::println);

        

       

    }


    

}

    

2.  EmployeeMax.class


public class EmployeeMax {

   private  String  name ; 

   private    int age;

   private   int salary ;

  

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public int getSalary() {

return salary;

}

public void setSalary(int salary) {

this.salary = salary;

}


public EmployeeMax(String name, int age, int salary) {

super();

this.name = name;

this.age = age;

this.salary = salary;

}

@Override

public String toString() {

return "EmployeeMax [name=" + name + ", age=" + age + ", salary=" + salary + "]";

}




}


Programm  output: 


Employee salary 30000

Employee salary 35000

Employee salary 40000

Employee salary 50000

Employee salary 77000

Short Employee using there salary  Short Employee  using there  salary Reviewed by Mukesh Jha on 2:49 AM Rating: 5

No comments:

Add your comment

All Right Reserved To Mukesh Jha.. Theme images by Jason Morrow. Powered by Blogger.