I am wondering if we can use index to access List
For example:
List list;
list[5] //blah....
an alternative to using get(int)
is to create an Array using toArray()
List<T> list = ...
Object[] array = list.toArray();
if T is known, toArray(T[])
can be used to return T[]
instead of Object[]
.
The use of toArray
is only meaningful, instead of get
, if an array is really needed (lots of accesses).