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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:28:10+00:00 2026-05-22T17:28:10+00:00

System.arraycopy() is a shallow copy method. For an array of a primitive type, it

  • 0

System.arraycopy() is a shallow copy method.

For an array of a primitive type, it will copy the values from one array to another:

int[] a = new int[]{1,2};
int[] b = new int[2];
System.arraycopy(a, 0, b, 0, 2);

b will be {1,2} now. Changes in a will not affect b.

For an array of a non-primitive type, it will copy the references of the object from one array to the other:

MyObject[] a = new MyObject[] { new MyObject(1), new MyObject(2)};
MyObject[] b = new MyObject[2];
System.arraycopy(a, 0, b, 0, 2);

b will contain a reference of new MyObject(1), new MyObject(2) now. But, if there are any changes to new MyObject(1) in a, it will affect b as well.

Are the above statements correct or not?

  • 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-22T17:28:11+00:00Added an answer on May 22, 2026 at 5:28 pm

    Above statements are correct or not?

    Yes, you are correct.

    System.arraycopy always does a shallow copy, no matter if the array contains references or primitives such as ints or doubless.

    Changes in array a will never affect array b (unless a == b of course).

    But if any changes of new MyObject(1) in a, it will affect b as well.

    Depends on what you mean. To be picky, a change to the new MyObject(1) will neither affect a nor b (since they only contain references to the object, and the reference doesn’t change). The change will be visible from both a and b though, no matter which reference you use to change the object.

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

Sidebar

Related Questions

The toArray method in ArrayList , Bloch uses both System.arraycopy and Arrays.copyOf to copy
System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length) is a native method.
I want to read from a txt file and I am using System.arraycopy to
System.IO.BinaryReader reads values in a little-endian format. I have a C# application connecting to
I was surprised to see in the Java source that System.arraycopy is a native
I have a String array in a Groovy class (args to a main method):
System.Windows.Forms.Form has only one scroll event- Scroll , but it is necessary to recognize
How do I print out the values of the byte array all at once?
i need some help regarding adding values into an array for example long[] s
Is Java's System.arraycopy() efficient for small arrays, or does the fact that it's a

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.