java - How to clone a container (f.e. ArrayList) *easily*? Is it wrong to use .clone()? -


my, perhaps naive, solution cloning arraylist (vector replacement) is

arraylist<double> albis = (arraylist<double>) aloriginal.clone(); 

considering because array contains immutable doubles, don't need clone them, container.

as clone() returns object put there cast, -xlint complains unchecked cast.

so, now? ignore supresswarnings? create new arraylist , copy orginal elements compact for? library method similar arrays.copyof()?

i read unchecked cast warning accepted way incredible complex.

clone() has major flaws, see this question reference. don't use it!

instead, standard collections have copy constructors. use them:

list<double> original = // list list<double> copy = new arraylist<double>(original); 

reference:


Comments

Popular posts from this blog

mod rewrite - Doing external redirect. .htaccess NS flag not working. How to achieve similar results? -

mysql - How to insert just year and month into date field? -