-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTraverse.java
58 lines (37 loc) · 1.43 KB
/
Traverse.java
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
/**
"LinkedList"
1). Java LinkedList class uses a doubly linked list to store the elements.
It provides a linked-list data structure. It inherits the AbstractList
class and implements List and Deque interfaces.
2). Java LinkedList class can contain duplicate elements.
3). Java LinkedList class maintains insertion order.
4). Java LinkedList class is non synchronized.
5). In Java LinkedList class, manipulation is fast because no shifting needs to occur.
6). Java LinkedList class can be used as a list, stack or queue.
7). Let's see the declaration for java.util.LinkedList class.
public class LinkedList<E> extends AbstractSequentialList<E> implements List<E>, Deque<E>,
Cloneable, Serializable.
*/
package linkedList;
import java.util.*;
public class Traverse
{
public static void main(String[] args)
{
LinkedList<String> li = new LinkedList<String>();
//ADD the element to the first Node
li.addFirst("SHAHID");
//Add the element to the Node
li.add("A");
//Add Element to the last Node
li.addLast("Iqbal");
//Retrieves and removes the first element of this list,or returns null if this list is empty.
li.pollFirst();
Iterator<String> it = li.descendingIterator();
while(it.hasNext())
{
//Returns the next element in the iteration.
System.out.println(it.next());
}
}
}