Employee Highest salary in each department using Java

Categories: Java Java Examples

Employee Highest salary in each department using Java

package r4r.co.in;

import java.util.ArrayList;

import java.util.Comparator;

import java.util.LinkedHashMap;

import java.util.List;

import java.util.Map;

import java.util.Optional;

import java.util.stream.Collectors;

public class EmployeeHighestSalaryInEachDepartment {

public static void main(String[] args) {

// Employee Highest salary in each department

List<Emp> list = new ArrayList<Emp>();

list.add(new Emp("Rajesh", 120, "IT"));

list.add(new Emp("Rajesh", 110, "IT"));

list.add(new Emp("Rajesh", 120, "ACT"));

list.add(new Emp("Rajesh", 110, "ACT"));

list.add(new Emp("Rajesh", 190, "OP"));

Map<Object, Object> map = list.stream().collect(Collectors.groupingBy(e -> e.getDep(), Collectors

.collectingAndThen(Collectors.maxBy(Comparator.comparingDouble(Emp::getSal)), Optional::get)));

System.out.println(map);

}

}

class Emp {

String name;
int sal;
String dep;

public Emp(String name, int sal, String dep) {

super();

this.name = name;

this.sal = sal;

this.dep = dep;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getSal() {

return sal;

}

public void setSal(int sal) {

this.sal = sal;

}

public String getDep() {

return dep;

}

public void setDep(String dep) {

this.dep = dep;

}

@Override

public String toString() {

return "Emp [name=" + name + ", sal=" + sal + ", dep=" + dep + "]";

}

}

Top Blogs
All about the java programming language Published at:- When and Why Java is utilized for Application Advancement Published at:- Tips to learn Java Programming Language Published at:- Key Advantages of Java Application Advancement to Assorted Organizations Published at:- Scanner nextLine() ,nextInt() ,nextDouble() method in Java with Examples Published at:- java toUpperCase() and toLowerCase() example Published at:- pushing value at last in java | how to add element at the end of array in java Published at:- fizzbuzz problem java Published at:- Write a program for group words by first character of given string | Java 8 Stream Example Published at:- Write a Java 8 program to calculate the age of a person in years given their birthday Published at:- Write a Java 8 program to calculate the age of a person in years given their birthday Years Months Days Published at:- Write a Java 8 program to print the first 10 odd numbers Published at:- Filter employees by age in Java 8 Lamda steam Published at:- Write a Java 8 program to get the last element of an array string/object Published at:- Filter employees by age set senior if age is greater than 30 in Java 8 Lamda steam Published at:- How to increment salary by 2%, 5%, etc. Using java Published at:- Write a program to find the only duplicate count list in the List Published at:- Write a program to append char in char ex-input- {A, B, C} output->[A_X, B_Y, C_Z] Published at:- Write a program to sum an array without using the sum method Published at:- Write a program to sum an array Published at:- Drop all while condition not meet dropWhile(),dropWhile(Predicate<T> predicate) Published at:- Find the maximum value in a list of integers using Stream & Method Reference Published at:- How to sort a list of strings by length using Lambda expressions Published at:- How to filter and collect a list of strings that start with a specific letter using Java 8 Stream Published at:- Write a Java program To create a map from a array of strings where the key is the string and the value is its length Published at:- How to count the number of occurrences of a given word in a list of strings using Java 8 Published at:- How to remove all duplicates from an array of integers in Java using Java 8 Published at:- How to find next, previous, tomorrow ,yesterday date using Java 8 Published at:- How to iterate and modify values in a Map using Java 8 Published at:- How to print keys & values of a Map using Java 8 Published at:- count of each character in a String using Java 8 Published at:- Write a Program to find the Maximum element in an array Published at:- How to check if list is empty in Java 8 using Optional Published at:- Find duplicate elements with its count using Java 8 Published at:- Find Last duplicate character of given string using Java 8 Published at:- Given a list of integers, separate odd and even numbers Published at:- Singleton Design Pattern and 7 Ways to Implement It 4 Ways to Break Singleton Design Pattern Published at:- java 8 using lambda expression and stream api | Java 8 Programs using Lambda Expression and Stream Published at:- 26 Java 8 Programs using Lambda Expression and Stream Published at:- Java 8 Stream String Null Or Empty Filter Published at:- sum ,min ,max etc example using reduce method using Java 8 Stream API Published at:- Sort highest salary in each department Published at:- Employee Highest salary in each department using Java Published at:- Grouping Employees by City and Age Published at:- Finding the Count of Male and Female Employees Published at:- Printing Names of All Departments from Employee Class using Java Published at:- Printing Employee Details by Age Criteria using Java Published at:- Finding Maximum Age of Employee using Java Published at:- Printing Average Age of Male and Female Employees using Java Published at:- Printing the Number of Employees in Each Department using Java Published at:- Java Class subclass interview coding questions Published at:- Child and Parent overridden methods Throws RuntimeException Published at:- Child and Parent overridden methods Throws checked exception Published at:- Find Customer staring with +91 mobile number Published at:- Concatenate String array into single string Published at:- Sorting the Employees Salary in Each Department in Descending Order Published at:- Sorting the Employees Salary in Each Department in Ascending Order Published at:- Knapsack top down dynamic programming using java Published at:- Subset Sum Problem SubSet Sum Problem Solution using Knapsack Published at:-
R4R.co.in Team
The content on R4R is created by expert teams.