Collections.synchronizedList(new ArrayList<>())
public static <T> List<T> synchronizedList(List<T> list) {
return (list instanceof RandomAccess ?
new SynchronizedRandomAccessList<>(list) :
new SynchronizedList<>(list));
}
SynchronizedList(List<E> list) {
super(list);
this.list = list;
}
SynchronizedCollection(Collection<E> c) {
this.c = Objects.requireNonNull(c);
mutex = this;
}
public void add(int index, E element) {
synchronized (mutex) {list.add(index, element);}
}
public E remove(int index) {
synchronized (mutex) {return list.remove(index);}
}
![](https://i-blog.csdnimg.cn/blog_migrate/bfecbfcc8b04b974c3679fb54513f298.png)