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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:35:31+00:00 2026-05-29T05:35:31+00:00

Are arrays in Java pass by reference or pass by value? Suppose I have

  • 0

Are arrays in Java pass by reference or pass by value?

Suppose I have an array called data that contains objects of some type. Now let us suppose that I pass and store that array in class A and then I pass it to class B and class B changes one of the entries of the array. Will class A’s version of the array change? Does it matter if this was an array of primitives (such as int) instead? What about ArrayLists?

  • 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-29T05:35:32+00:00Added an answer on May 29, 2026 at 5:35 am

    Everything in Java is pass-by-value. However, if you’re passing a reference, it’s the value of the reference.

    Since Java methods can’t reach into the caller’s stack to reassign variables, no method call can change the identity of a reference (address) there. This is what we mean when we say Java is not pass-by-reference. This contrasts with C++ (and similar languages), which allows this in some cases.

    Now let’s look at some effects.

    If I do:

    Object[] o = ...
    mutateArray(o);
    

    the contents can be different afterwards, since all mutateArray needs is the address of an array to change its contents. However, the address of o will be the same. If I do:

    String x = "foo";
    tryToMutateString(x);
    

    the address of x is again the same afterwards. Since strings are immutable, this implies that it will also still be "foo".

    To mutate an object is to change the contents of it (e.g. successfully changing the last element of o, or trying to change the last letter of “foo” to ‘d’). This should not be be confused with reassigning x or o in the caller’s stack (impossible).

    The Wikipedia section on call by sharing may shed additional light.

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

Sidebar

Related Questions

I have a 10x10 array in Java, some of the items in array which
I have a bidimensional Object array in Java. Some indices aren´t used, because they
Can you pass a new array as a method, and still have data in
I want to pass 2 arrays to a function in Java and have them
How can I pass an array by reference in Java? For instance I need
I have some image processing Java code in Android that acts upon two large
I have some MATLAB code and some Java code that need to talk with
Possible Duplicate: Is Java pass by reference? I have a question about passing by
In my page I have an applet. I'd like to pass a some data
Its known that Java ArrayList is implemented using arrays and initializes with capacity 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.