Skip to content

EmployeeProcessing

Usage

    List<Employee> list = new ArrayList<>();
    IO.println(Runtime.getRuntime().freeMemory());
    list.add(new Employee(1, "Swapnil", 10000.0));
    list.add(new Employee(2, "Yogesh", 20000.0));
    list.add(new Employee(3, "Doctor", 30000.0));
    list.add(new Employee(4, "Bhaiyaa", 40000.0));
    list.add(new Employee(5, "Kuwar", 50000.0));
    List<String> with3kGreaterSalary = list.stream().filter(s -> s.getSalary() > 3000.0).map(Employee::getName).toList();
    List<Employee> with10perHike = list.stream().map(s -> new Employee(s.getId(), s.getName(), s.getSalary() * 1.1)).toList();
    Employee highestSalEmp = list.stream().max(Comparator.comparing(Employee::getSalary)).orElse(null);

getSmallestPositiveMissingNumber

Integer getSmallestPositiveMissingNumber(List<Integer> list) {
    int smallest = 1;
    Set<Integer> set = new HashSet<>(list);
    while (set.contains(smallest)) {
        smallest++;
    }
    return smallest;
}

Employee

class Employee {

    Integer id;

    String name;

    Double salary;

    public Employee(Integer id, String name, Double salary) {
        this.id = id;
        this.name = name;
        this.salary = salary;
    }

    public Integer getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public Double getSalary() {
        return this.salary;
    }

    public void setSalary(Double sal) {
        this.salary = sal;
    }
}