The Collections
and Arrays
classes offer
several ways of manipulating the elements within a List
or array. There are no additional ways to manipulate the other
key framework interfaces (Set
and Map
).
With a List
, the Collections
class lets you
replace every element with a single element, copy an entire list
to another, reverse all the elements, or shuffle them around.
When copying from one list to another, if the destination list is
larger, the remaining elements are untouched.
void fill(List list, Object element)
void copy(List source, List destination)
void reverse(List list)
void shuffle(List list)
void shuffle(List list, Random random)
The Arrays
class allows you to replace an entire
array or part of an array with one element via eighteen
overridden versions of the fill()
method. All the
methods are of the form fill(array, element)
or fill(array,
fromIndex, toIndex, element)
.