java howto ArrayList push, pop, shift, and unshift

前端 未结 5 479
我在风中等你
我在风中等你 2020-12-12 17:19

I\'ve determined that a Java ArrayList.add is similar to a JavaScript Array.push

I\'m stuck on finding ArrayList functions sim

5条回答
  •  盖世英雄少女心
    2020-12-12 17:19

    maybe you want to take a look java.util.Stack class. it has push, pop methods. and implemented List interface.

    for shift/unshift, you can reference @Jon's answer.

    however, something of ArrayList you may want to care about , arrayList is not synchronized. but Stack is. (sub-class of Vector). If you have thread-safe requirement, Stack may be better than ArrayList.

提交回复
热议问题