Can we use index like array index to access List?

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

I am wondering if we can use index to access List

For example:

List list; 

list[5]     //blah....
7条回答
  •  Happy的楠姐
    2020-12-03 07:35

    No, you're restricted to List.get (i).

    The brackets [] are defined on syntax level, not as method-name, so you can't override them. They are used just for arrays exclusively.

    If you like to migrate to Scala, a more modern language for the JVM, you'll find an unified access to arrays and lists, but both with () parentheses.

提交回复
热议问题