java - How to make a copy of ArrayList object which is type of List? -
I have read the Java value from the near object context, and to make a local copy of the object, I can either Am clone () or copy constructor
I now see the example:
list & lt; String & gt; List = New Arrestist & lt; String & gt; (); String one = "a" list.add (a);
Some articles I've read, only mention that the Arrayist is capable of cloning, but in reality it is not said how to make a local copy of "list", if type The list is not listed, which is not listed which is not clonable.
I can call the clone () if there is an array list of type "list".
ArrayList & lt; String & gt; List = New Arrestist & lt; String (); List.clone ();
But if there is a list of types, then I can not.
Can I just use the copy maker to make a local copy? What is the best way to copy "list"?
list & lt; String & gt; TmpList = New Arrestist & lt; String & gt; (List);
Passing the manufacturer into the list Perhaps the best way to go is Constructor invocation, curtains Behind the system Will use arrecopy. Therefore, it will effectively separate the local copy from the list passed through the constructor.
Comments
Post a Comment