Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: array copy!!!

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    My Mood
    Worried
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Red face array copy!!!

    ok so I am trying to learn about arrays, and I found thee on a book that you can use the arraycopy method to do it more simple
    so I did these code with the directions It is really not a big deal but I cannot figure out what is wrong I keep getting the same error that I need object, and I have arrays, but I found it under arrays topic. maybe is so dumb I am donīt see it. I would appreciate some help.
    the code is the following
     public class  ArrayCopy{
     
          public static void main(String[]args){
     
             int[]sourceArray={1,2,3,5,3,6};
     
             int[]targetArray= new int[6];
     
             System.arraycopy(sourceArray, 0, targetArray, 0);
     
          for( int i =0; i<targetArray.length; i++)
     
          System.out.println("Taget Array");
          System.out.println( targetArray[i] + " " );
     
          }}



    thankss


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: array copy!!!

    What errors are you getting (specifically)? If you're getting compile errors or runtime exceptions, please post the exact error message (text please, not screen-shots).

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    Username (May 13th, 2013)

  4. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    My Mood
    Worried
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: array copy!!!

    ArrayCopy.java:11: error: method arraycopy in class System cannot be applied to given types;
    System.arraycopy(sourceArray, 0, targetArray, 0);
    ^
    required: Object,int,Object,int,int
    found: int[],int,int[],int
    reason: actual and formal argument lists differ in length
    ArrayCopy.java:16: error: cannot find symbol
    System.out.println( targetArray[i] + " " );
    ^
    symbol: variable i
    location: class ArrayCopy
    2 errors

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.

  5. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: array copy!!!

    check your {}

  6. The Following User Says Thank You to jps For This Useful Post:

    Username (May 13th, 2013)

  7. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    My Mood
    Worried
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Cool Re: array copy!!!

    I was missing one of the last statements in the arraycopy.
    I
    got it thank you!!

Similar Threads

  1. Copy Constructor
    By Rhyssa6 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 7th, 2021, 09:12 PM
  2. I need help for this copy byte code ...
    By ricaclaire16 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 26th, 2012, 08:00 AM
  3. Array in constructor and deep copy.
    By Ejii in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 29th, 2011, 08:34 PM
  4. Deep copy of ArrayList?
    By Scotty in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 29th, 2011, 01:30 PM
  5. program a button that copy whatever in a JTextArea
    By voltaire in forum AWT / Java Swing
    Replies: 5
    Last Post: May 17th, 2010, 12:43 AM