I know that ArrayList is not thread safe and I've seen many people recommending
converting it in (Collections.synchronizedList) . I need to create a system where I convert my ArrayList to (Collections.synchronizedList) and then back to ArrayList. But first I need to insert a in b.
The problem is that I do not know how to convert from (Collections.synchronizedList) to ArrayList and I get an error when I try to insert the following element:
public List<Object> a;
public List<ArrayList<Object>> b;
a = Collections.synchronizedList(new ArrayList<Object>());
b = Collections.synchronizedList(b);
When I try the following command an exception is thrown:
b.add(id, (ArrayList<Object>) a);
java.base/java.util.Collections$SynchronizedRandomAccessList cannot be cast to java.base/java.util.ArrayList