File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import data .PersonModel ;
2+
3+ import java .util .LinkedList ;
4+ import java .util .ListIterator ;
5+
6+ public class TheLinkedList {
7+
8+ public static void main (String [] args ) {
9+ LinkedList <PersonModel > rockers = new LinkedList <>();
10+
11+ rockers .add (new PersonModel ("Tupac" , 26 ));
12+ rockers .add (new PersonModel ("Biggie" , 25 ));
13+ rockers .addFirst (new PersonModel ("Big L" , 22 ));
14+ rockers .add (2 , new PersonModel ("Paul" , 35 ));
15+
16+ ListIterator <PersonModel > iterator = rockers .listIterator ();
17+
18+ while (iterator .hasNext ()) {
19+ System .out .println (iterator .next ());
20+ }
21+
22+ System .out .println ();
23+
24+ while (iterator .hasPrevious ()) {
25+ System .out .println (iterator .previous ());
26+ }
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ import data .PersonModel ;
2+
13import java .util .LinkedList ;
24import java .util .Queue ;
35
46public class TheQueue {
57
68 public static void main (String [] args ) {
7- Queue <Person > market = new LinkedList <>();
8- market .add (new Person ("Raheem" , 21 ));
9- market .add (new Person ("Nargeeza" , 21 ));
10- market .offer (new Person ("Islam" , 11 ));
9+ Queue <PersonModel > market = new LinkedList <>();
10+ market .add (new PersonModel ("Raheem" , 21 ));
11+ market .add (new PersonModel ("Nargeeza" , 21 ));
12+ market .offer (new PersonModel ("Islam" , 11 ));
1113
1214 System .out .println (market .size ());
1315 System .out .println (market .peek ());
@@ -16,30 +18,4 @@ public static void main(String[] args) {
1618 System .out .println (market .remove ());
1719 System .out .println (market .peek ());
1820 }
19-
20- private static class Person {
21- private final String name ;
22- private final int age ;
23-
24- public Person (String name , int age ) {
25- this .name = name ;
26- this .age = age ;
27- }
28-
29- public String getName () {
30- return name ;
31- }
32-
33- public int getAge () {
34- return age ;
35- }
36-
37- @ Override
38- public String toString () {
39- return "Person{" +
40- "name='" + name + '\'' +
41- ", age=" + age +
42- '}' ;
43- }
44- }
4521}
Original file line number Diff line number Diff line change 1+ package data ;
2+
3+ public class PersonModel {
4+ private final String name ;
5+ private final int age ;
6+
7+ public PersonModel (String name , int age ) {
8+ this .name = name ;
9+ this .age = age ;
10+ }
11+
12+ public String getName () {
13+ return name ;
14+ }
15+
16+ public int getAge () {
17+ return age ;
18+ }
19+
20+ @ Override
21+ public String toString () {
22+ return "Person{" +
23+ "name='" + name + '\'' +
24+ ", age=" + age +
25+ '}' ;
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments