Sometimes when we need to replicate ArrayList, the quickest way is to create a new instance, in fact each collection class has a corresponding construction method that is copied by itself. The Clone () method itself is defective and is not recommended for use. The recommended practices are as follows:
list<double> original =//some listlist<double> copy = new arraylist<double> (original);
The problem is found when you do the HBase project, and when scanner gets the next result, if you add the result directly to the result set and re-use the ArrayList, the final result set will be the last result.
The Modified code:
list<cell> curvals = new arraylist<cell> (); list<list<cell>> results = new arraylist<list<cell>> (); Boolean finish = False;do {Curvals.clea R (); finish = Scanner.next (curvals); list<cell> tmp = new arraylist<cell> (curvals); Copy intermediate result Results.add (TMP);} while (finish);
Article original link: http://stackoverflow.com/questions/715650/how-to-clone-arraylist-and-also-clone-its-contents
Java-Replication ArrayList