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 2 of 2

Thread: copy an array

  1. #1
    Junior Member
    Join Date
    Feb 2021
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default copy an array

    I have to make an array copy and the second one have to repeat 3 times as array1 = [1,2,3], arrayB =[1,2,3,1,2,3,1,2,3], what I have so far:
    public static void repeat(int[] array)
    {
    int[] arrayB = new int[array.length];


    for (int i = 0; i < array.length; i++)
    {

    arrayB[i] = array[i];

    }
    System.out.println(" the new array values is: " + Arrays.toString(arrayB));
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: copy an array

    What problems do you have? Are there any errors?


    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. copy() to copy the values of singly linked list1 to another linked list
    By ritika3 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 25th, 2017, 07:16 AM
  2. How do i copy this single dimension array?
    By cgskook in forum Algorithms & Recursion
    Replies: 3
    Last Post: December 6th, 2013, 11:06 PM
  3. How to copy one array into another and flip the values
    By ghostheadx in forum What's Wrong With My Code?
    Replies: 8
    Last Post: September 9th, 2013, 03:27 PM
  4. array copy!!!
    By Username in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 13th, 2013, 02:53 PM
  5. 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