Highest Salary In Each Department Using Java8 {हिन्दी}

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.ย. 2024
  • Highest Salary In Each Department using Java 8 .
    This code creates a Stream of all the employees and groups them with their department with the help of Collectors.groupingBy. For all the values classified to the same key, we need to keep only the employee with the maximum salary, so we collect them with Collectors.maxBy and the comparator compares the salary with Comparator.comparingInt. Since maxBy returns an Optional "Employee " (to handle the case where there the list is empty), we wrap it with a call to Collectors.collectingAndThen with a finisher that just returns the employee: we know in this case that the optional won't be empty.

ความคิดเห็น • 6

  • @PrateevaPolai
    @PrateevaPolai ปีที่แล้ว +1

    I tried this code and it only fetches a single employee getting highest salary from each department. Even though there are multiple employees getting same highest salary. Can you write a code to fetch all the employees from each department getting highest salary. for example 2 employees from HR department gets the same highest salary 10000. So in output I want both the employee details.

  • @hackstreet781
    @hackstreet781 ปีที่แล้ว

    They have created streams so that we don't have to use our brains to think on the logic and simply learn the infinite number of functions and try to find a way to use them. Streams api is completely useless, I can't think complex logic in streams. Streams are not made for humans , they are made for machines.

  • @alok7485
    @alok7485 ปีที่แล้ว

    Can you write a program to get top 5 salaries and Employees name given they have Employee ID , Employee NAme , Employee Department , Employee Salary , Employee isActive boolean true property.
    Please explain in easy words and execute and write program using java 8 functional programming features and streams to Pick only the TOP 5 salary and top 5 Employee Name only.
    I tried with this following approach but interviewer rejected me and i am not able to solve. Please explain how to write the solution because i am crying so much.
    public class Employee {
    //id,name,department,salary,isActive;
    //Find out top 5 IT department, e.salary)))));
    }
    }

    • @hackstreet781
      @hackstreet781 ปีที่แล้ว +1

      Streams are waste of time. For interviews, I have to byheart the code for different programs and I can't simply think in terms of streams. I want to personally punch the java creators for creating streams.

    • @alok7485
      @alok7485 ปีที่แล้ว

      @@hackstreet781 please gimme ur email id and lets by heart together different interview questions

    • @Krishnadevaraya1
      @Krishnadevaraya1 3 หลายเดือนก่อน

      max by gives only one value