-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkedlist.java
51 lines (34 loc) · 1.11 KB
/
Linkedlist.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
package core;
import java.util.LinkedList;
public class Linkedlist {
public static void main(String[] args) {
LinkedList<String> phones = new LinkedList<String>();
phones.add("Apple");
phones.add("Samsung");
phones.add("Moto");
phones.add("Spark");
phones.add("Oppo");
System.out.println(phones);
//Check If an Item Exists
System.out.println(phones.contains("Moto"));
//Adds an item to the beginning of the list
phones.addFirst("Vivo");
System.out.println(phones);
//Add an item to the end of the list
phones.addLast("Mi");
System.out.println(phones);
//Remove an item from the beginning of the list
System.out.println(phones.removeFirst());
//Remove an item from the end of the list
System.out.println(phones.removeLast());
//Get the item at the beginning of the list
System.out.println(phones.getFirst());
//Get the item at the end of the list
System.out.println(phones.getLast());
//Loop through an LinkedList
for(int i=0;i<phones.size();i++)
{
System.out.println(phones.get(i));
}
}
}