Equivalent of std::vector in Java?

后端 未结 9 1273
名媛妹妹
名媛妹妹 2020-12-15 03:16

What would be the closest thing to a std::vector in Java? By this I mean, a class which can take in T into its constructor and then pushBack, popBack() and that is stored in

9条回答
  •  难免孤独
    2020-12-15 03:34

    You're probably looking for the ArrayDeque which supports push/pop style access from both ends of the list efficiently.

    Avoid Stack and Vector - these are synchronized, which implies generally pointless overhead.

    ArrayList is also fine; however, you'd need to implement your own (trivial) pop method since it is not provided by the class itself. ArrayList does permit indexed access, which ArrayDeque lacks.

提交回复
热议问题