我刚刚读了一些 information在 Vector
和 ArrayList
上。据我所知,与 ArrayList
相比,Vector
已过时。但是 Vector
是同步的,而 ArrayList
不是。
但这意味着什么呢?当我们说 Vector
是同步的时,这意味着什么?这在什么时候有用?
最佳答案
这意味着多个线程可以并行修改 Vector 而没有数据损坏的风险。
如果要对 ArrayList 执行此操作,则需要使用 synchronized
关键字。
关于java - synchronized 在 Vector/ArrayList 的上下文中意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10376983/