Namely, without referencing the same object, I need to copy values of elements of one list into another list. These are the lists:
List listA = ne
There is absolutely no reason to make a copy of an Integer. Integer is an immutable class. This means that its value is set when the Integer instance is created, and can never change. An Integer reference can thus be shared by multiple lists and threads without fear, because there's no way anybody can change its value. Your question thus makes no real sense.
To create an ArrayList b
containing the same Integers as another List a
, just use the following code:
List b = new ArrayList(a);
Sure the Integer won't be cloned, but this is a good thing, because cloning them is completely unnecessary.