java set collection list LinkedList details
- 2020-05-30 20:18:55
- OfStack
As follows:
import java.util.*;
/*
LinkedList: Specific methods:
addFirst();
addLast();
getFirst();
getLast();
Gets the element, but does not delete it. If there is no element in the set, it will appear NoSuchElementException
removeFirst();
removeLast();
Gets the element, but the element is deleted. If there is no element in the set, it will appear NoSuchElementException
in JDK1.6 Alternatives have emerged.
offerFirst();
offerLast();
peekFirst();
peekLast();
Gets the element, but does not delete it. If there is no element in the collection, it returns null .
pollFirst();
pollLast();
Gets the element, but the element is deleted. If there is no element in the collection, it returns null .
*/
class LinkedListDemo
{
public static void main(String[] args)
{
LinkedList link = new LinkedList();
link.addLast("java01");
link.addLast("java02");
link.addLast("java03");
link.addLast("java04");
//sop(link);
// sop(link.getFirst());
// sop(link.getFirst());
//sop(link.getLast());
//sop(link.removeFirst());
//sop(link.removeFirst());
//sop("size="+link.size());
while(!link.isEmpty())
{
sop(link.removeLast());
}
}
public static void sop(Object obj)
{
System.out.println(obj);
}
}
/*
---
java01
java02
java03
java04
----
java04
java03
java02
java01
---
*/