File tree Expand file tree Collapse file tree
out/production/java-data-structures Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import java .util .LinkedList ;
2+ import java .util .Queue ;
3+
4+ public class TheQueue {
5+
6+ 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 ));
11+
12+ System .out .println (market .size ());
13+ System .out .println (market .peek ());
14+ System .out .println (market .poll ());
15+ System .out .println (market .size ());
16+ System .out .println (market .remove ());
17+ System .out .println (market .peek ());
18+ }
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+ }
45+ }
You can’t perform that action at this time.
0 commit comments