Sign in to follow this  

[Java]putting element from array 1 to different index in array 2

This topic is 4693 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i summed up best i could in the title. Here's my dilemma: (in Java) i want to loop through PART of one array (say in an array of length 8: start from 4th index and go to 8th) and insert those elements into another array starting from index 0. This method below doesn't work, for obvious reasons: for (int i = 0; i < array1.length-index; i++) { for (int j = index; j < array1.length; j++) { array2[i] = array1[j]; } } //end i thought i would have 'i' loop through the second array and 'j' loop through the first. But, of course, the inner 'for' loop gets fully executed before moving on to the next index... so how do i make it so one step through the second array(array2) corresponds to one step through the first array? or perhaps i am asking the wrong question? thanks in advance y'all

Share this post


Link to post
Share on other sites

This topic is 4693 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this