Benefits of arrays

Posted by Vitalii Fedorenko on Stack Overflow See other posts from Stack Overflow or by Vitalii Fedorenko
Published on 2010-05-16T13:31:04Z Indexed on 2010/05/16 13:40 UTC
Read the original article Hit count: 193

Filed under:
|
|
|
|

As I see it, the advantages of List over array are pretty obvious:

  • Generics provide more precise typing: List<Integer>, List<? extends Number>, List<? super Integer>.
  • List interface has a bunch useful methods: addAll, remove etc. While for arrays all standard operations except get/set must be performed in a procedure manner by passing it to a static method.
  • Collections offer different implementations like ArrayList, LinkedList, unmodifieable and synchronized lists, which can be hidden under common List interface.
  • OOB length control.

As disadvantages I can only mention absence of syntactic sugar and runtime type check. At the same time supporting of both structures requires frequent using of asList and toArray methods, which makes code less readable. So I am curious if there are any important benefits of using arrays that I miss.

© Stack Overflow or respective owner

Related posts about java

Related posts about arrays