online
The Java 2 Platform SpecificationBooks
Thinking in Java by Bruce EckelCore Java (TM) 2 Volume 1 - Fundamentals by Cay Horstmann and Gary Cornell
ArrayList ArrayListName = new ArrayList();
ArrayList ArrayListName = new ArrayList(5); //The 5 sets the initial element capcaity. The default is 10.
ArrayList ArrayListName = new ArrayList(collectionIn); //creates a new ArrayList with the elements of a collection. //Elements are read from the collection with an Iterator.
int arrayListSize = arrayListName.size();
boolean isArrayListEmpty = arrayListName.isEmpty();
int objectFirstFoundAt = arrayListName.indexOf(objectToSearchFor);
int objectLastFoundAt = arrayListName.lastIndexOf(objectToSearchFor);
boolean isObjectInArrayList = arrayListName.contains(objectToSearchFor);
Object objectName = (ClassTypeToCastTo) arrayListName.get(intOffsetToGetElementAt); //note: Objects coming out of ArrayLists have lost // their class type, and must be cast
boolean addWasGood = arrayListName.add(objectToAdd); //inserts at end
arrayListName.add(intOffsetToSetElementAt, objectToAdd); //inserts at offset, no boolean returned
arrayListName.addAll(collectionToAdd); arrayListName.addAll(intOffsetToAddCollectionAt, collectionToAdd);
arrayListName.set(intOffsetToSetElementAt, objectIn); //replaces element at offset
arrayListName.remove(intOffsetToRemoveElementAt); //deletes element at offset
arrayListName.removeRange (intOffsetToRemoveElementFromInclusive, intOffsetToRemoveElementToExclusive); //deletes from start offset up to the end offset //note - element at the end offset is not deleted
arrayListName.clear();
Object[] arrayToCopyArrayListInto = arrayListName.toArray();
| Sign In |
| to add the first comment for Java ArrayLists. |