Last active
December 19, 2015 13:48
-
-
Save lichenbo/5964260 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| E elementData(int index) { | |
| return (E) elementData[index]; | |
| } | |
| public E get(int index) { | |
| rangeCheck(index); | |
| return elementData(index); | |
| } | |
| public E set(int index, E element) { | |
| rangeCheck(index); | |
| E oldValue = elementData(index); | |
| elementData[index] = element; | |
| return oldValue; | |
| } | |
| private void rangeCheck(int index) { | |
| if (index >= size) | |
| throw new IndexOutOfBoundsException(outOfBoundsMsg(index)); | |
| } | |
| public int indexOf(Object o) { | |
| if (o == null) { | |
| for (int i = 0; i < size; i++) | |
| if (elementData[i]==null) | |
| return i; | |
| } else { | |
| for (int i = 0; i < size; i++) | |
| if (o.equals(elementData[i])) | |
| return i; | |
| } | |
| return -1; | |
| } | |
| public int lastIndexOf(Object o) { | |
| if (o == null) { | |
| for (int i = size-1; i >= 0; i--) | |
| if (elementData[i]==null) | |
| return i; | |
| } else { | |
| for (int i = size-1; i >= 0; i--) | |
| if (o.equals(elementData[i])) | |
| return i; | |
| } | |
| return -1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment