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 6780851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:33:17+00:00 2026-05-26T16:33:17+00:00

I have been playing around with Bundle.putStringArrayList ArrayList<String> myArrayList = new ArrayList<String>(); ArrayList<String> keys

  • 0

I have been playing around with Bundle.putStringArrayList

  ArrayList<String> myArrayList = new ArrayList<String>();
  ArrayList<String> keys = new ArrayList<String>();
  Bundle name_bundle = new Bundle();
  for (int i = 0; 10 > i; i++){

        myArrayList.add(i + " first");
        myArrayList.add(i + " second");
        keys.add(i + " key");

        name_bundle.putStringArrayList(keys.get(i), myArrayList);
        myArrayList.clear();
  }

I would expect the output (when debugging) to be (after running the loop a couple of times, but not to completion):

Bundle[{2 key=[2 first, 2 second], 1 key=[1 first, 1 second], 0 key=[0 first, 0 second]}]

However, it is:

Bundle[{2 key=[2 first, 2 second], 1 key=[2 first, 2 second], 0 key=[2 first, 2 second]}]

Is this a bug, or is this how it is intended to work? And if so, is it because it is reusing the same array?

Since the key is different ever time, I am not sure why it would over write every value.

Especially since this:

  ArrayList<String> keys = new ArrayList<String>();
  Bundle name_bundle = new Bundle();
  for (int i = 0; 10 > i; i++){
    keys.add(i + " key");
    String s = i + " string";
    name_bundle.putString(keys.get(i), s);
  }

Produces this (after running the loop a couple of times):

Bundle[{2 key=2 string, 1 key=1 string, 3 key=3 string, 0 key=0 string}]

EDITED

When using the following:

            ArrayList<String> one = new ArrayList<String>();
    ArrayList<String> two = new ArrayList<String>();
    ArrayList<String> tmpkey = new ArrayList<String>();
    one.add("1 first array");
    one.add("2 first array");
    two.add("1 second array");
    two.add("2 second array");
    tmpkey.add("first key");
    tmpkey.add("second key");
    name_bundle.putStringArrayList(tmpkey.get(0), one);
    name_bundle.putStringArrayList(tmpkey.get(1), two);

You get:

Bundle[{first key=[1 first array, 2 first array], second key=[1 second array, 2 second array]}]

The fact that it requires new arraylists kind of defeats the purpose of being able to reuse an arraylist by using .clear(), however.

Just to verify, when adding the following to the end of the above:

    one.clear();
    one.add("will it work?");
    name_bundle.putStringArrayList(tmpkey.get(2), one);

You get:

Bundle[{third key=[will it work?], first key=[will it work?], second key=[1 second array, 2 second array]}]

Is anyone aware of a work-around wherein I can reuse the arraylist so I can use it in a loop? Or perhaps a different approach all together? The reason I went for a loop is because I didn’t know how many times I would have to reuse the arraylist, or since it doesn’t allow you to, how many arraylists I would need.

  • 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-26T16:33:18+00:00Added an answer on May 26, 2026 at 4:33 pm

    You are calling #clear() on your myArrayList & reusing it – causing all keys to reference the same list (until/if they are parceled I guess). Try allocating a new ArrayList for each call to #putStringArrayList(...).

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

Sidebar

Related Questions

I have been playing around with ElasticSearch for a new project of mine. I
I have been playing around with different caching strategies on Heroku and have add
I have been playing around with variadic templates in the new c++ standard and
I have been playing around with the postgresql.conf file for a couple days now.
I have been playing around with the EF to see what it can handle.
I have been playing around with the MS Source Server stuff in the MS
I have been playing around a bit with a fairly simple, home-made search engine,
I have been playing around with the MVP pattern using winforms for the last
I have been playing around with the Rhino ETL library and really like the
I have been playing around with NSURLConnection. Now I'm trying to grab some data

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.