java.util.List

说明:An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list. 

继承关系:Collection->list->ArrayList 

主要的函数: booleanadd(E e)  Appends the specified element to the end of this list

void add(int index, E element)
          Inserts the specified element at the specified position in this list

Object get(int index)
          Returns the element at the specified position in this list.

int indexOf(Object o)
          Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

boolean isEmpty()
          Returns true if this list contains no elements.

 Object remove(int index)
          Removes the element at the specified position in this list 

boolean remove(Object o)
          Removes the first occurrence of the specified element from this list, if it is present

int size()
          Returns the number of elements in this list.

Object[] toArray()
          Returns an array containing all of the elements in this list in proper sequence (from first to last element).

ArrayList~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ArrayList()
          Constructs an empty list with an initial capacity of ten.

ArrayList(int initialCapacity)
          Constructs an empty list with the specified initial capacity.

void clear()
          Removes all of the elements from this list.

 E get(int index)
          Returns the element at the specified position in this list.

Eclipse常用快捷键:

alt + / 快速填充函数 ctrl + shift + o 自动import 

windows->preference->java->formatter 设置格式化

windows->preference->Editor->Content assist 去掉fill mthod arguments and show guessed 

主要源代码:

public ArrayList() {
this(10);
    }

public ArrayList(int initialCapacity) {
super();
        if (initialCapacity < 0)
            throw new IllegalArgumentException("Illegal Capacity: "+
                                               initialCapacity);
this.elementData = new Object[initialCapacity];
    }

 private transient Object[] elementData;

public boolean add(E e) {
ensureCapacity(size + 1);  // Increments modCount!!
elementData[size++] = e;
return true;
    }

public void ensureCapacity(int minCapacity) {
modCount++;
int oldCapacity = elementData.length;
if (minCapacity > oldCapacity) {
   Object oldData[] = elementData;
   int newCapacity = (oldCapacity * 3)/2 + 1;
        if (newCapacity < minCapacity)
newCapacity = minCapacity;
            // minCapacity is usually close to size, so this is a win:
            elementData = Arrays.copyOf(elementData, newCapacity);
}
    }



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值