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

  • SEARCH
  • Home
  • 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 7645417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:56:12+00:00 2026-05-31T09:56:12+00:00

I have an arraylist populated by four elements, the order of which is random

  • 0

I have an arraylist populated by four elements, the order of which is random (they are put here by random from another arraylist). I then have a for loop that repeats 10 times, at the end of each repetition I use the clear methods to clear all the elements of the arraylist. However, when I start a new repetition, I would like to repopulate my arraylist with the old (previously worked with) elements that were members of the list in the previous repetition, so that I can use the elements again. And I would like to repeat that until I get out of my 10-repetition for loop. Is there any way to achieve this at all?

Code in addition to my question:

 ArrayList<String> answerPegs =  new  ArrayList<String>();
  // add element to ArrayList

    ArrayList<String> mySecretAnswer = new ArrayList<String>();

    for (int n = 4; n > 0; n--) 
    {       
         //populate mySecretAnswer with elements from answerPegs
    }


    ArrayList<String> clone1 = mySecretAnswer;

    for (int q = 0; q < 10; q++) { 

        for (o = 0; o < 4; o++)
        {
         }
      // called clear() method here

    } // END OF 10-ROW LOOP
  • 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-31T09:56:13+00:00Added an answer on May 31, 2026 at 9:56 am

    I would suggest simply having 2 lists – keep a pristine copy of the original list, and then iterate over + clear a copy of that list.

    public void doRepetitions(List<Object> original)
    {
        for( int i=0; i<10; i++ )
        {
            List<Object> working = new ArrayList<Object>( original );
            doStuffWithList(working);
        }
    }
    

    Edit:
    Since you’ve posted your code, I can give a more specific answer:

    You can change your clone to be:

    ArrayList<String> clone1 = new ArrayList<String>(mySecretAnswer);
    

    And then move that to be inside your for loop:

    for (int q = 0; q < 10; q++)
    { 
        ArrayList<String> clone1 = new ArrayList<String>(mySecretAnswer);
        // ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ArrayList made up of different elements imported from a db, made
I have a ListView with custom adapter which is populated from local sqlite database.
I have a heavily populated arraylist, which I want to clear and reuse. If
I have a html form which is populated using a java for loop. And
I have an ArrayList<String> , and I want to remove repeated strings from it.
I have an arraylist which has a class datastructure. public class empRec { public
I have a listview that's populated by rows that get their data from a
I am using an ArrayList within my code which gets populated by a EditText
in c# if i have an arraylist populated like (ID, ITEMQUANTITY), and i would
I am working with an arraylist populated by downloading files referenced from an RSS

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.