The following will give you an array of the type you want while preserving type safety.
PCB[] getAll(Class<PCB[]> arrayType) {
PCB[] res = arrayType.cast(java.lang.reflect.Array.newInstance(arrayType.getComponentType(), list.size()));
for (int i = 0; i < res.length; i++) {
res[i] = list.get(i);
}
list.clear();
return res;
}
How this works is explained in depth in my answer to the question that Kirk Woll linked as a duplicate.