Can we use index like array index to access List?

后端 未结 7 777
失恋的感觉
失恋的感觉 2020-12-03 06:45

I am wondering if we can use index to access List

For example:

List list; 

list[5]     //blah....
相关标签:
7条回答
  • 2020-12-03 07:47

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

    0 讨论(0)
提交回复
热议问题