How do I clone a generic List in Java?

前端 未结 14 2007
轻奢々
轻奢々 2020-11-27 12:38

I have an ArrayList that I\'d like to return a copy of. ArrayList has a clone method which has the following signature:



        
14条回答
  •  情书的邮戳
    2020-11-27 13:07

    I find using addAll works fine.

    ArrayList copy = new ArrayList();
    copy.addAll(original);
    

    parentheses are used rather than the generics syntax

提交回复
热议问题