Can we use index like array index to access List?

后端 未结 7 798
失恋的感觉
失恋的感觉 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:30

    Since [] is an operator and java does not support operator overloading you can't use it with List. Instead you have to use the set(int index, T value) and get(int index) methods, which may be verbose but provide exact the same functionality.

提交回复
热议问题