Thursday, October 20, 2011

List in Java

LinkedList, ArrayList, Vector, and Stack all implement this interface.

Important methods on this interface:

add(Object)
add(index, Object)
addAll(Collection)
addAll(index, Collection)
clear()
contains(Object)
containsAll(Collection)
equals(Object)
get(index) //return object
indexOf(Object)
isEmpty()
size()
iterator()
subList(index, index) //return List
toArray()
iterator()
set(index, element), replace specified postion with the passed in element
retainAll(Collection)
removeAll(Collection)
remove(Object)
remove(index)
lastIndexOf(Object) //return index of the last occurrence of this object


ArrayList:
clone()
toString()
removeRange(fromIndex, toIndex)


Vector:
clone()
toString()
elementAt(index)
setElementAt(Object, index)
firstElement()
ElementAtIndex(index)
removeAllElements()
removeRange(fromIndex, toIndex)


Stack, last-in-first-out (LIFO), extends vector
empty()
peek()
pop()
push()
search(object)


LinkedList //implements Deque Interface
descendingIterator - Returns an iterator over the elements in this deque in reverse sequential order.
removeFirst()
removeLast()
removeFirstOccurance(Object)
removeLastOccurance(Object)
peekFirst/Last() //retrieve and don't remove
offerFirst/Last() //insert
pollFirst/Last() //retrieves and removes

No comments:

Post a Comment