Yes, Just be careful if you are also iterating over the list, because in this case you will need to synchronize on it. From the Javadoc:
It is imperative that the user manually synchronize on the returned list when iterating over it:
List list = Collections.synchronizedList(new ArrayList());
...
synchronized (list) {
Iterator i = list.iterator(); // Must be in synchronized block
while (i.hasNext())
foo(i.next());
}
Or, you can use CopyOnWriteArrayList
which is slower for writes but doesn't have this issue.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…