package java_test; import java.util.LinkedList; public class LinkedListDemo { public static void main(String[] args) { // TODO Auto-generated method stub LinkedList link = new LinkedList(); link.addFirst("abc1"); link.addFirst("abc2"); link.addFirst("abc3"); //演示 XXX first XXXlast 方法 //获取,只返回 // System.out.println(link.getFirst());//abc3 // System.out.println(link.getFirst());//abc3 //remove方法删除的同时,还会返回删除的元素 // System.out.println(link.removeFirst());//abc3 // System.out.println(link.removeFirst());//abc2 //取出元素 while(!link.isEmpty()) System.out.println(link.removeLast()); } }
运行结果:
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco }
abc1
abc2
abc3
时间: 2024-11-05 11:49:46