Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7079569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:41:17+00:00 2026-05-28T06:41:17+00:00

Possible Duplicate: How to clone ArrayList and also clone its contents? I have a

  • 0

Possible Duplicate:
How to clone ArrayList and also clone its contents?

I have a ArrayList<Widget> that I would like to “deep” clone so that making modifications to any items in the original list does not have any effect on the items in the cloned list:

ArrayList<Widget> origList = getMyList();
ArrayList<Widget> cloneList = origList.clone();

// Remove the 5th Widget from the origina list
origList.remove(4);

// However, the cloneList still has the 5th Widget and is unchanged

// Change the id of the first widget
origList.get(0).setId(20);

// However in cloneList, the 1st Widget's ID is not 20

What’s the best/safest way of accomplishing this? I imagine that it’s not as simple as:

ArrayList<Widget> cloneList = origList.clone();

I imagine the fact that this is a built-in ArrayList type, plus the fact that its generic, are going to complicate things. I also imagine I will need to write a special clone() override for my Widget class?

Thanks in advance!

Edit:
I’d also be completely receptive if there is a commons JAR out there that does this heavy lifting for me, so please feel free to make suggestions, however I would still like to know how to do this the ole’ fashion way so I can learn 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:41:17+00:00Added an answer on May 28, 2026 at 6:41 am

    This is a non-trivial task, I suggest you use one of the available libraries such as http://code.google.com/p/cloning/

    See also: Java: recommended solution for deep cloning/copying an instance

    If you want to see how it’s done get an open-source library and look at the source 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Java: how to clone ArrayList but also clone its items? I have
Possible Duplicate: How to clone ArrayList and also clone its contents? trying to make
Possible Duplicate: comparing contents of two files using python I have a file name
Possible Duplicate: How do I clone a generic list in C#? hey i have
Possible Duplicate: What is the best way to clone/deep copy a .NET generic Dictionary<string,
Possible Duplicate: What is the most efficient way to clone a JavaScript object? I
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: What is the most efficient way to clone a JavaScript object? How
Possible Duplicate: PHP last day of the month Is there any function like $date->getMonthDays()
Possible Duplicate: The Definitive C++ Book Guide and List i have a lot of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.