-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemployeedetailobject.java
More file actions
49 lines (44 loc) · 1.57 KB
/
employeedetailobject.java
File metadata and controls
49 lines (44 loc) · 1.57 KB
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
39
40
41
42
43
44
45
46
47
48
49
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.Optional;
class EmployeeeObjects{
int empid;
String name;
public EmployeeeObjects(int empid,String name) {
this.empid=empid;
this.name=name;
}
}
public class employeedetailobject {
public static void main(String[] args) {
ArrayList<EmployeeeObjects> al = new ArrayList<>();
al.add(new EmployeeeObjects(10,"Helllo"));
al.add(null);
al.add(new EmployeeeObjects(120,"H90elllo"));
al.add(new EmployeeeObjects(432,null));
for (EmployeeeObjects elem : al) {
if(Optional.ofNullable(elem).isPresent())
{
Optional.ofNullable(elem).ifPresent((i)->{
System.out.println("Employee Object found!! ID: "+i.empid);
});
System.out.println("Emp name : "+elem.name+" id: "+elem.empid);
}
else{
System.out.println("Employee not found! or null value present");
}
}
System.out.println("Now we will print using iterator: ");
@SuppressWarnings("rawtypes")
ListIterator itr = al.listIterator();
while (itr.hasNext()) {
EmployeeeObjects elem = (EmployeeeObjects) itr.next();
if(Optional.ofNullable(elem).isPresent()){
System.out.println("Emp name : "+elem.name+" id: "+elem.empid);
}
else{
System.out.println("Employee not found! or null value present");
}
}
}
}