Zusammenfassung der Ressource
ArrayLists
- Resizable-array
implementation
of the List
interface.
- is an abstraction from programmer
manipuplation of Arrays
- part of Collections API
- Implements
all optional
List
operations
- elements
can be any
object type
and null
- uses generics<T>
- create new ArrayList object
- ArrayList<String> list = new ArrayList<String>()
- deafault size at creation is 10. can specify
required size as constructor parameter
- specify class name of objects it will hold in <>.
can use empty <> after new.
- Array is used as underlying
hidden data structure
- size increases
automatically if
add to full
arraylist
- METHODS
- size: number of indices
with elements
- int x = list.size()
- remove element
- remove & return element
at index i : E
elem=list.remove(i);
- remove 1st
match of
element e: boolean b
= list.remove(e);
- remove all
elements:
list.clear();
- add element
- add element at end:
list.add("something")
- insert at position of index:
list.add(i, elem)
- replace element:
list.set(index, "something
else");
- get element at index
i: E e= list.get(i);
- list.contains(e)
- list.isEmpty();
- for-each or enhanced
for loop can be used
- ArrayList vs Array
- AL: less efficient; not have
convenient[ i] use; base type must
be a class, not primitive(can use
wrappers);
- A: can't change in size - AL
grow/shrink during use; A: need to
keep cnt of elements in it- AL: does
this auto; A: have NO methods - AL:
powerful methods for manipulation