ArrayList and parsing source code

1, an array of introduction

Because arrays are sequentially stored in the data storage, the memory is stored in continuous, which is characterized by the data easier to read
, difficult to remove insert

Analysis 2.arraylist source
  1) the constructor (the default capacity of 10)

  2) inserting a data
  expansion operation newCapacity = oldCapacity + oldCapacity >> 1

  3) delete operation

  4) traversal
  arraylist remove elements during traversal being given
  for (Integer NUM: List) {
    IF (== 12 is NUM)
    list.remove ();
  }

  Iterator can be deleted by
  the Iterator <Integer> = list.iterator IT ();
  the while (it.hasNext ()) {
    Integer it.next NUM = ();
    IF (== 12 is NUM) {
      it.remove () ;
    }
  }

Guess you like

Origin www.cnblogs.com/houchen/p/11665470.html