MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / main

Method main

collections/LinkedListFeatures.java:9–38  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

7
8public class LinkedListFeatures {
9 public static void main(String[] args) {
10 LinkedList<Pet> pets =
11 new LinkedList<>(new PetCreator().list(5));
12 System.out.println(pets);
13 // Identical:
14 System.out.println(
15 "pets.getFirst(): " + pets.getFirst());
16 System.out.println(
17 "pets.element(): " + pets.element());
18 // Only differs in empty-list behavior:
19 System.out.println("pets.peek(): " + pets.peek());
20 // Identical; remove and return the first element:
21 System.out.println(
22 "pets.remove(): " + pets.remove());
23 System.out.println(
24 "pets.removeFirst(): " + pets.removeFirst());
25 // Only differs in empty-list behavior:
26 System.out.println("pets.poll(): " + pets.poll());
27 System.out.println(pets);
28 pets.addFirst(new Rat());
29 System.out.println("After addFirst(): " + pets);
30 pets.offer(new PetCreator().get());
31 System.out.println("After offer(): " + pets);
32 pets.add(new PetCreator().get());
33 System.out.println("After add(): " + pets);
34 pets.addLast(new Hamster());
35 System.out.println("After addLast(): " + pets);
36 System.out.println(
37 "pets.removeLast(): " + pets.removeLast());
38 }
39}
40/* Output:
41[Rat, Manx, Cymric, Mutt, Pug]

Callers

nothing calls this directly

Calls 5

listMethod · 0.80
peekMethod · 0.80
getMethod · 0.65
removeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected