Help the world stop coronavirus! Stay home!

Prev Next

Java / Arrays

How do I create a list from Array which is completely independent of the original array?

The fixed length list returned by asList method is used as an argument to create a new ArrayList which is later garbage collected.

The new ArrayList is independent of the original array and the changes to the list does not reflect on the array and vice versa.

Adding/removing elements could be performed in this list.

String[] myFruits1 = { "Apple", "Pineapple", "Strawberry" };
List<String> myFruitsList = new ArrayList<String>(Arrays.asList(myFruits1));      

❤Cash Back At Stores you Love !!!❤

Earn your $10 reward when you make your first purchase through Ebates by signing up with clicking below button.

Ebates Coupons and Cash Back

More Related questions...

Show more question and Answers...


Comments & Discussions