Home Java SCJP SCWCD Servlet Submit News Contact Us Site Map


Over 500 magazines for free (including Oracle Magazine)!

Yes all of them are FREE. You can subscribe to ALL of them.
Click here to apply today!

Replacing the specified element of the Java ArrayList

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.

Getting 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.


Removing 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.

<< Search Elements from Java ArrayList

Java ArrayList Example >>

Home Java SCJP SCWCD Servlet Site map