LinkedList的特有功能


import java.util.Iterator;
import java.util.LinkedList;

public class LinkedListDemo {

	public static void main(String[] args) {
		LinkedList<String> link = new LinkedList<String>();
		link.add("wo");
		link.add("ai");
		link.add("xue");
		link.add("xi");
		
		//linkedList 特有的功能
		link.addFirst("hello");
		link.addLast("bye");
		System.out.println(link);
		System.out.println("----------------");
		System.out.println("removeLast" + link.removeLast());
		
		System.out.println("----------------");
		System.out.println("getFirst"+link.getFirst());
		
		System.out.println("----------------");
		
		Iterator<String> iterator  = link.iterator();
		
		while (iterator.hasNext()) {
			String string = iterator.next();
			System.out.println(string);
		}
		
		
	}
}

你可能感兴趣的:(LinkedList的特有功能)