Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By dojob

Thread: arraycopy function

  1. #1
    dojob is offline Member
    Join Date
    Jul 2013
    Posts
    52
    Rep Power
    0

    Default arraycopy function

    Java Code:
        public static void main(String[] args) {
            int[] sourceArray = {2, 3, 1, 5, 10};
            int[] targetArray = new int[sourceArray.length];
            
            System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length);
            for(int i = 0;i < sourceArray.length; i++){
                System.out.println(targetArray);
            }
       }
    and I get the following output.

    [I@4a200bde
    [I@4a200bde
    [I@4a200bde
    [I@4a200bde
    [I@4a200bde
    Have i done any mistake?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,304
    Rep Power
    20

    Default Re: arraycopy function

    No, that's the expected output.

    Now if what you really wanted was to print each element of the array, then you need to supply the index in the argument to the println statement.

    Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    dojob is offline Member
    Join Date
    Jul 2013
    Posts
    52
    Rep Power
    0

    Default Re: arraycopy function

    thanks. i realise the mistake i made. It should be System.out.println(targetArray[i]).
    DarrylBurke likes this.

Similar Threads

  1. Recursive function to iteractive function
    By mikeZet in forum New To Java
    Replies: 0
    Last Post: 03-13-2012, 01:42 AM
  2. Problem with arrayCopy
    By _rapt0r_ in forum New To Java
    Replies: 2
    Last Post: 11-24-2011, 11:50 PM
  3. Help with System.arrayCopy
    By sehudson in forum New To Java
    Replies: 3
    Last Post: 02-22-2011, 03:28 AM
  4. copy arrays without using arraycopy Method !
    By M7MD in forum Introductions
    Replies: 0
    Last Post: 10-10-2010, 06:59 PM
  5. Replies: 3
    Last Post: 12-04-2009, 03:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •