How can I rewrite my code without using concurrent collections?
public static void main(String[] args) {
ArrayList<Integer> source = new ArrayList<>();
for(int i = 0; i < 5; i++) {
source.add(i);
}
List<Integer> synchList = Collections.synchronizedList(new ArrayList<>());
Runnable runnable = () -> {synchList.addAll(source);};
}
List<Integer> synchList = Collections.synchronizedList(new ArrayList<>( ));withList<Integer> synchList = new ArrayList<>();. In the code you’ve posted, there is no need for any synchronization. If you want to do something different, post the relevant code instead of a pointless snippet.