search

Home  >  Q&A  >  body text

java中的Stack还推不推荐用?

好像之前在 thinking in java中看到过说Stack类继承于Vector,而这两个类都不推荐使用了,但是在做一到OJ题时,我用LinkedList来模拟栈和直接用Stack,发现在进行入栈出栈操作时Stack的速度竟然还快一点,有点疑惑了..

黄舟黄舟2786 days ago805

reply all(3)I'll reply

  • PHPz

    PHPz2017-04-17 14:46:24

    Use the appropriate data structure for the appropriate scenario.
    I have only used Stack when doing formula calculations, but I rarely use it at other times and it has no impact. So it still depends on your business scenario, and you should use it.

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 14:46:24

    Not recommended
    The advantage is thread safety, so single-threaded ArrayList and the like are better.
    However, when multi-threading is needed, there are Collections.synchronizedList and the java.util.concurrent package. So forget about this thing.

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 14:46:24

    When the sample size of computationally intensive code is small, the accidental error of performance testing is relatively large

    reply
    0
  • Cancelreply