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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:18:58+00:00 2026-06-08T12:18:58+00:00

I have two separate objects ArrayList<String> in two separate packages Top and top10. I

  • 0

I have two separate objects ArrayList<String> in two separate packages Top and top10. I assign the value of top10 to Top in my activity. And now if I remove an element from Top it also gets removed from top10. I don’t know why is this happening? I feel totally dumbfounded. Is there something I don’t know about java? Or is it android?

This is my activity code:

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

// ServiceCall is the name of the class where top10 is initialized.

Top = ServiceCall.top10;

System.out.println("top WR: "+ServiceCall.top10);

if(Top.get(0).equals("Please Select")) Top.remove(0);   

System.out.println("top WR: "+ServiceCall.top10);

The second printed out statement has one element less than the one before.

  • 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-06-08T12:18:59+00:00Added an answer on June 8, 2026 at 12:18 pm

    You are pointing Top to top10, not creating a new list (your initializer is effectively unused right now, as you are just repointing it to the other list.)

    You should do:

    ArrayList<String> Top = new ArrayList<String>(ServiceCall.top10);    
    

    This will create a shallow copy.

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

Sidebar

Related Questions

Hello I have problem to put together animations of two separate objects to second
I have two separate objects, a main and a child. Its physically not a
I have created two separate objects, one of class Order and one of class
bit of an odd question here. If I have two separate objects, each with
I am currently designing a master detail gridview. I have two separate objects defined
I have two separate objects in Java, Object1 and Object2 , both are the
We have two separate web-apps, say 'retailUI' and 'bulkUI'. These two are basically two
I have two separate applications (both part of the same system) that share a
I have two separate caches running in a JVM (one controlled by a third
I have two separate sets of tables in the same database that model the

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.