黑马程序员技术交流社区

标题: 有关LinkedList的方法引用 [打印本页]

作者: 崔一恒    时间: 2013-7-11 11:36
标题: 有关LinkedList的方法引用
本帖最后由 崔一恒 于 2013-7-11 21:49 编辑
  1. import java.util.*;
  2. class LinkedListDemo
  3. {
  4.         public static void main(String[] args)
  5.         {
  6.                 LinkedList link =new LinkedList();
  7.                 link.addLast("java01");
  8.                 link.addLast("java02");
  9.                 link.addLast("java03");
  10.                 link.offerLast("02");        
  11.                 link.addLast("java04");
  12.                

  13.                 System.out.println(link);
  14.         }
  15. }
复制代码
其中addLastt和offerLast都是将指定元素插入到此列表的末尾,那就是说这两个在任何情况下两者可以互相替换?

作者: 小石头39910    时间: 2013-7-11 11:49
void addLast(E e)  将指定元素添加到此列表的结尾。 返回值是void 直接将元素插入
boolean offerLast(E e)  在此列表末尾插入指定的元素。 返回值是布尔类型的,用于判断,性质是不相同的,谈不上互换
作者: changweihua    时间: 2013-7-11 11:56
Inserts the specified element at the front of this deque unless it would violate capacity restrictions. When using a capacity-restricted deque, this method is generally preferable to the addFirst(E) method, which can fail to insert an element only by throwing an exception.
在不违反容量限制的情况下,将指定的元素插入此双端队列的末尾。当使用有容量限制的双端队列时,此方法通常优于 addLast(E) 方法,后者可能无法插入元素,而只是抛出一个异常。
作者: 崔一恒    时间: 2013-7-11 21:48
每天逛逛论坛




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2