java@ LinkedList 学习

时间:2022-09-19 20:35:51
package abc.com;

import java.util.LinkedList;

public class TestLinkedList {

    static void prt(Object o) {
System.out.print(o);
}
public static void main(String[] args) {
// TODO Auto-generated method stub LinkedList<Character> books = new LinkedList<Character>(); books.offerFirst('a');
books.offerLast('b');
books.offerLast('c');
books.offerFirst('d'); for(int i=0;i<books.size();++i) {
prt(books.get(i));
}prt("\n"); prt(books.peekFirst() + "\n"); prt(books.peekLast() + "\n"); prt(books); books.pollFirst(); prt(books); prt(books); books.pollLast(); prt(books); } }
运行结果:
dabc
d
c
[d, a, b, c] [a, b, c]
[a, b, c] [a, b]