成都网站建设设计

将想法与焦点和您一起共享

ArrayList的陷阱!谁知道?

 
 
 
  1. import java.util.ArrayList;     
  2.     
  3.     
  4. public class ArrayListTest {     
  5.     public static void main(String[] args) {     
  6.         //一个物件链表     
  7.         ArrayList  strAl= new ArrayList ();     
  8.         strAl.add("a");     
  9.         strAl.add("b");     
  10.         strAl.add("c");     
  11.         strAl.add("d");     
  12.         //要删除物件链表的所有索引     
  13.         ArrayList  indexes= new ArrayList ();     
  14.         indexes.add(0);     
  15.         indexes.add(2);     
  16.         //逐个删除     
  17.         for (int i = 0; i < indexes.size(); i++) {     
  18.             strAl.remove(indexes.get(i));     
  19.         }     
  20.         //打印***物件个数     
  21.         System.out.println(strAl.size());     
  22.     }     
  23. }     
  24.     
  25. //谁能不运行代码,知道打印出来是多少呢    

分享文章:ArrayList的陷阱!谁知道?
分享路径:http://chengdu.cdxwcx.cn/article/dhcogej.html