System.arraycopy(...)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bucketbot
    New Member
    • May 2007
    • 9

    #1

    System.arraycopy(...)

    If I have an array A and I wanted to copy it into a larger array, how would I do that with the arraycopy(...) method?

    thanks
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by bucketbot
    If I have an array A and I wanted to copy it into a larger array, how would I do that with the arraycopy(...) method?

    thanks
    And what do the docs say about System.arraycop y?

    Comment

    • bucketbot
      New Member
      • May 2007
      • 9

      #3
      I wouldn't be posting here if I hadn't already looked at it. I don't understand how the parameters work for it. for ex:

      system.arraycop y(the source array, the index you want to start copying from, the destination array, ?, ?)

      along with those 2 question marks, where do you make the destination array?

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by bucketbot
        I wouldn't be posting here if I hadn't already looked at it. I don't understand how the parameters work for it. for ex: system.arraycop y(the source array, the index you want to start copying from, the destination array, ?, ?) along with those 2 question marks, where do you make the destination array?
        Which docs did you check?

        Quote = docs

        arraycopy (Object src, int srcPos, Object dest, int destPos, int length)

        Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination array.

        Comment

        • shorab777
          New Member
          • Oct 2007
          • 1

          #5
          /**
          *
          */
          import java.lang.Syste m;

          /**
          * @author 72hosh1mst
          *
          */
          public class arrayofcopy {

          /**
          * @param args
          */
          public static void main(String[] args) {
          // TODO Auto-generated method stub
          char [] a1={'a','b','c' ,'d','e','f'};
          char [] b1={'x','y','z' ,'u','v'};

          System.arraycop y(a1,1,b1,2,3);
          System.out.prin tln(b1);



          }

          }

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by bucketbot
            I wouldn't be posting here if I hadn't already looked at it. I don't understand how the parameters work for it. for ex:

            system.arraycop y(the source array, the index you want to start copying from, the destination array, ?, ?)

            along with those 2 question marks, where do you make the destination array?
            What's the problem then? That method copies data from one array (the source)
            to another array (the destination). The method wants to know the start offset
            in both arrays as well as the number of elements to copy and there it goes.

            kind regards,

            Jos

            Comment

            Working...