码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA 集合类

时间:2015-11-02 19:05:29      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

常用

1 ArrayList 动态数组

技术分享
 1     /**
 2      * Default initial capacity.
 3      */
 4     private static final int DEFAULT_CAPACITY = 10;
 5 
 6     public ArrayList(int initialCapacity) {
 7         super();
 8         if (initialCapacity < 0)
 9             throw new IllegalArgumentException("Illegal Capacity: "+
10                                                initialCapacity);
11         this.elementData = new Object[initialCapacity];
12     }
13 
14     public ArrayList() {
15         super();
16         this.elementData = EMPTY_ELEMENTDATA;
17     }
18 
19     public ArrayList(Collection<? extends E> c) {
20         elementData = c.toArray();
21         size = elementData.length;
22         // c.toArray might (incorrectly) not return Object[] (see 6260652)
23         if (elementData.getClass() != Object[].class)
24             elementData = Arrays.copyOf(elementData, size, Object[].class);
25     }
26     
27     public boolean add(E e) {
28         ensureCapacityInternal(size + 1);  // Increments modCount!!
29         elementData[size++] = e;
30         return true;
31     }
32 
33     public E get(int index) {
34         rangeCheck(index);
35 
36         return elementData(index);
37     }
View Code

 

  

 

JAVA 集合类

标签:

原文地址:http://www.cnblogs.com/jason-Z/p/4930802.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!