Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
1) Object set(int index, Object element)
Replaces the element at specified index with the object passed as a parameter. Returns the previous element that has been replaced.
Get element from the ArrayList
1) Object get(int index)
Returns the element at the specified index in the ArrayList. Note : We need to downcast the returned object to the desired type.
Remove elements from the ArrayList
1) Object remove(int index)
Removes the elements at the specified index in the list and shifts the subsequent element of the list by one. This method returns the element that has been removed from the list. This method can throw IndexOutOfBoundException if the index specified is out of range.
2) void removeRange(int startIndex, int endIndex)
Removes the elements from list whose index is between startIndex inclusive and endIndex exclusive and shifts the subsequent elements of the list.
3) void clear()
Removes all elements of the ArrayList.
Convert ArrayList in to an Object array
1) Object[] toarray()
Returns array of Object containing all elements of the ArrayList in the correct order.
This brings us end of Java ArrayList Tutorial. Please let us know your views by leaving comment in comments section below.
<< Search Elements in ArrayList Java ArrayList Example >>

Post new comment