java中的Stack还推不推荐用?
黄舟
黄舟 2017-04-17 14:44:24
0
3
727

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

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all (3)
PHPzhong

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.

    刘奇

    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.

      刘奇

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

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!