-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayListTest.java
More file actions
83 lines (62 loc) · 2.31 KB
/
Copy pathArrayListTest.java
File metadata and controls
83 lines (62 loc) · 2.31 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Iterator;
public class ArrayListTest {
public static void main(String[] args) {
System.out.println("Creating the content....");
PhoneLog log1 = new PhoneLog("You missed a call", LocalDate.now(), "Missed", "Reeta");
PhoneLog log2 = new PhoneLog("You dialed a call", LocalDate.now(), "Dialed", "Anjali");
PhoneLog log3 = new PhoneLog("You recieved a call", LocalDate.now(), "Recieved", "Shivani");
PhoneLog log4 = new PhoneLog("You got a sms", LocalDate.now(), "Message In", "Sapna");
PhoneLog log5 = new PhoneLog("You missed a call", LocalDate.now(), "Missed", "Priya");
System.out.println("Content is creaeted....");
System.out.println("Creating container....");
ArrayList<PhoneLog> phoneLogList = new ArrayList<PhoneLog>();
System.out.println("Container is ready....");
System.out.println("Adding the 1 element....");
phoneLogList.add(log1);
System.out.println("Adding the 2 element....");
phoneLogList.add(log2);
System.out.println("Adding the 3 element....");
phoneLogList.add(log3);
System.out.println("Adding the 4 element....");
phoneLogList.add(log4);
System.out.println("Adding the 5 element....");
phoneLogList.add(log5);
System.out.println("---> Now iterating over the container <---");
Iterator<PhoneLog> iterator = phoneLogList.iterator();
//Iterator<PhoneLog> iterator = new ArrayList<PhoneLog>().iterator();
while(iterator.hasNext()) {
PhoneLog theLog = iterator.next();
System.out.println("The Log : "+theLog);
}
}
}
class Log
{
String logMessage;
LocalDate logTime;
public Log(String logMessage, LocalDate logTime) {
super();
this.logMessage = logMessage;
this.logTime = logTime;
}
@Override
public String toString() {
return "Log [logMessage=" + logMessage + ", logTime=" + logTime + "]";
}
}
class PhoneLog extends Log
{
String logType;
String logBy;
public PhoneLog(String logMessage, LocalDate logTime, String logType, String logBy) {
super(logMessage, logTime);
this.logType = logType;
this.logBy = logBy;
}
@Override
public String toString() {
return "PhoneLog [toString()=" + super.toString() + ", logType=" + logType + ", logBy=" + logBy + "]";
}
}