【转载】新知识点:JAVA List.add(int,object)

转载地址:http://blog.sina.com.cn/s/blog_6819fa800100lwr6.html

  1.函数原型

    void add(int index, E element)

  在列表的指定位置插入指定元素(可选操作)。将当前处于该位置的元素(如果有的话)和所有后续元素向右移动(在其索引中加 1)。

  2.参数:

index - 要在其中插入指定元素处的索引
element - 要插入的元素
 

  3.抛出:

UnsupportedOperationException - 如果列表不支持 add 操作
ClassCastException - 如果指定元素的类不允许它添加到此列表
NullPointerException - 如果指定的元素为 null,并且此列表不允许 null 元素
IllegalArgumentException - 如果指定元素的某些属性不允许它添加到此列表
IndexOutOfBoundsException - 如果索引超出范围 (index < 0 || index > size())

  4.举例:

   for(int i=0;i<this.pagination.getList().size();i++){      

      Seed s = null;      

      s = (Seed)this.pagination.getList().get(i);      

       int count = mySeedMng.countSeedsBySeedId(s.getId());       //运用了同一个引用,所以修改s的数据后,相应的list的数据也自动修改了      

      s.setViewerNum(count);  

   }

原文地址:https://www.cnblogs.com/LiesSu/p/3848973.html