File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

clone lists or objects

 
nimo frey
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to copy/clone a list of Objects:


// copy reference
s.setNames(s1.getNames());


how can I copy the value instead of the reference?

Is that right?:

// copy Value instead of reference
s.setNames(new ArrayList<Name>(s1.getNames));

Or is there a other way?
 
Steve Luke
Bartender
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is the correct way to make a new ArrayList with the same contents of the list returned by getNames() - so yeah, copying the value. It does not create new Name objects inside the list, those values will still be shared between both lists.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic