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

Thread: How do i copy this single dimension array?

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do i copy this single dimension array?

    ***000***
    ***000***
    ***000***

    pixels1[] =
    (***000******000******000***)
    I need to copy the star values

    ******
    ******
    ******

    pixels2[] =
    (******************)
    Into a shorter array

    Needs to be flexible i.e

    ****0000****
    ****0000****
    ****0000****
    ****0000****
    -->
    ********
    ********
    ********
    ********

    copy of 1 dimensional[] (theoretically 2d) based on height from pixels1[] --> pixels2[]

    I don't know if this makes any sense, but any ideas would be helpful. There has to be some algorithm for it, but i can figure it out. Extra: how does one generate an algorithm for stuff like this?


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: How do i copy this single dimension array?

    Eliminating the zeros? Count the zeros and create a new array that contains only the correct number of asterisks.

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How do i copy this single dimension array?

    there is no ryme or reason to the values, i just used stars and zeroes

    i need to copy and array from array1 --> array2
    array1--> /----\ height(5)
    {xxxxxyyyyyxxxxx xxxxxyyyyyxxxxx xxxxxyyyyyxxxxx xxxxxyyyyyxxxxx xxxxxyyyyyxxxxx}
    array2
    {xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx}

    i can get the height and width of both the arrays too

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: How do i copy this single dimension array?

    There does appear to be a rhyme or reason to every example you've posted, but if that was a mistake, then start by using the Arrays methods to do what you need and go from there. You can find an explanation of the available methods on the Arrays API page.

Similar Threads

  1. array copy!!!
    By Username in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 13th, 2013, 02:53 PM
  2. Single dimension array to multidimension array
    By 07.350 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 7th, 2013, 09:03 PM
  3. error: array dimension missing x 2. Any help?
    By giga in forum What's Wrong With My Code?
    Replies: 7
    Last Post: June 30th, 2012, 09:50 AM
  4. 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
  5. [SOLVED] How to declare an object of multi-dimension array?
    By FongChengWeng in forum Collections and Generics
    Replies: 7
    Last Post: January 14th, 2011, 01:17 AM