Java HashSet vs Array Performance

后端 未结 5 965
情书的邮戳
情书的邮戳 2020-12-30 07:50

I have a collection of objects that are guaranteed to be distinct (in particular, indexed by a unique integer ID). I also know exactly how many of them there are (and the n

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-30 08:28

    theoretically, and as SCJP6 Study guide says :D

    arrays are faster than collections, and as said, most of the collections depend mainly on arrays (Maps are not considered Collection, but they are included in the Collections framework)

    if you guarantee that the size of your elements wont change, why get stuck in Objects built on Objects (Collections built on Arrays) while you can use the root objects directly (arrays)

提交回复
热议问题