Java Reference
In-Depth Information
Useful Methods of ArrayList Objects
Method
Description
ArrayList<String>
example
Adds the given value at the
end of the list
add(value)
list.add("end");
Adds the given value at the
given index, shifting
subsequent values right
add(index, value)
list.add(1, "middle");
Removes all elements from
the list
clear()
list.clear();
Returns true if the given
value appears in the list
contains(value)
list.contains("hello")
Gets the value at the given
index
get(index)
list.get(1)
Returns the index of the first
occurrence of the given value
in the list ( -1 if not found)
indexOf(value)
list.indexOf("world")
Returns the index of the last
occurrence of the given value
in the list ( -1 if not found)
lastIndexOf(value)
list.lastIndexOf("hello")
Removes the value at the
given index, shifting subse-
quent values left
remove(index)
list.remove(1);
Replaces the given value at
the given index with the
given value
set(index, value)
list.set(2, "hello");
Returns the current number
of elements in the list
size()
list.size()
 
 
Search WWH ::




Custom Search