gpt4 book ai didi

java - 如何使用 Java8 流在下面的数组列表中找到第二高的薪水

转载 作者:行者123 更新时间:2023-12-05 08:30:20 25 4
gpt4 key购买 nike

<分区>

class Employee
{
int id;

String name;

int age;

String gender;

String department;

int yearOfJoining;

double salary;

public Employee(int id, String name, int age, String gender, String department, int yearOfJoining, double salary)
{
this.id = id;
this.name = name;
this.age = age;
this.gender = gender;
this.department = department;
this.yearOfJoining = yearOfJoining;
this.salary = salary;
}

public int getId()
{
return id;
}

public String getName()
{
return name;
}

public int getAge()
{
return age;
}

public String getGender()
{
return gender;
}

public String getDepartment()
{
return department;
}

public int getYearOfJoining()
{
return yearOfJoining;
}

public double getSalary()
{
return salary;
}

@Override
public String toString()
{
return "Id : "+id
+", Name : "+name
+", age : "+age
+", Gender : "+gender
+", Department : "+department
+", Year Of Joining : "+yearOfJoining
+", Salary : "+salary;
}
}

List<Employee> employeeList = new ArrayList<Employee>();

employeeList.add(new Employee(111, "Jiya Brein", 32, "Female", "HR", 2011, 25000.0));
employeeList.add(new Employee(122, "Paul Niksui", 25, "Male", "Sales And Marketing", 2015, 13500.0));
employeeList.add(new Employee(133, "Martin Theron", 29, "Male", "Infrastructure", 2012, 18000.0));
employeeList.add(new Employee(144, "Murali Gowda", 28, "Male", "Product Development", 2014, 32500.0));
employeeList.add(new Employee(155, "Nima Roy", 27, "Female", "HR", 2013, 22700.0));

Optional<Employee> emp = employeeList.stream()
.collect(Collectors.maxBy(Comparator.comparingDouble(Employee::getSalary)));

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com