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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:29:55+00:00 2026-05-23T12:29:55+00:00

i was reading about how you can only pass by value in java and

  • 0

i was reading about how you can only pass by value in java and that the only way to swap the contents of two objects is by putting then in an array…passing the reference to the array object by value and then using that reference to swap 0-1 array location.

But i have a further question on this:
Suppose i create an array such as:

List<Integer> array = new ArrayList<Integer>();
Integer a = new Integer(1);
array.add(a);

So my question is when i “add” an object to an array (in this case Integer object)…do I just store the reference to the object in the array or do I actually copy the content of the object in the array…

Hypothetically, let’s say we have a “delete reference” statement in java,..so will this retain the value of the object in the array?

List<Integer> array = new ArrayList<Integer>();
Integer a = new Integer(1);
array.add(a);
delete a;

So will the array still hold the correct value??

  • 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-23T12:29:56+00:00Added an answer on May 23, 2026 at 12:29 pm

    Hypothetically, let’s say we have a “delete reference” statement in java,..so will this retain the value of the object in the array?

    Since we do not know what this hypothetical statement is doing, that is hard to tell.

    What your ArrayList holds is a reference to an Integer object. Any other reference you have to that object points to the exact same instance.

    With Integer, that does not make much of a difference, because Integer is immutable.

    Try with a mutable object like StringBuilder to see the effect:

    List<Object> array = new ArrayList<Object>();
    StringBuilder a = new StringBuilder("xxxxxx");
    array.add(a);
    
    a.setLength(0);  // clear the contents
    
    System.out.println(array.get(0));  // will not print "xxxxxx" anymore
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been reading about the new developer-only RC0 for Silverlight, and the fact that
I've been reading about the 'only' keyword but can't find a definitive answer to
I keep reading about C99 and C++11 and all these totally sweet things that
I keep reading about people who are test infected, meaning that they don't just
Reading about the problem of creating a read only primitive vector in C# (basically,
I am reading about memory addressing. I read about segment offset and then about
I've been reading about the Jquery UI selectable plugin, my question is: Can I
Reading about the G.729 codec , I found this interesting tidbit about Comfort Noise
When reading about SQL Injection and XSS i was wondering if you guys have
I am reading about COFF file formats, which is commonly used to create an

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.