-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployeeList.java
More file actions
38 lines (31 loc) · 907 Bytes
/
EmployeeList.java
File metadata and controls
38 lines (31 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.util.*;
class Employee {
String name;
int id;
double salary;
Employee(String name, int id, double salary) {
this.name = name;
this.id = id;
this.salary = salary;
}
public String toString() {
return name + " | ID: " + id + " | Salary: " + salary;
}
}
public class EmployeeList {
public static void main(String[] args) {
ArrayList<Employee> list = new ArrayList<>();
list.add(new Employee("Aman", 101, 50000));
list.add(new Employee("Parul", 102, 60000));
list.add(new Employee("Divya", 103, 55000));
// Update salary of ID 102
for (Employee e : list) {
if (e.id == 102) e.salary = 65000;
}
// Remove employee with ID 101
list.removeIf(e -> e.id == 101);
for (Employee e : list) {
System.out.println(e);
}
}
}