How to hashMap an array in Java?

Adding specific elements from one array into another in Java?

  • Hi I'm stuck. I want to add the contents in index 4 of array 1 into index 0 of array 2 then add the contents of index 4+32 in array 1 to index 1 of array 2 and so forth. The index 6 array 1 into index 2 in array 2. I have tried everything including converting the first array into a list but it just gets messy. I would like to do this: for (int ab = 0; ab <5; ab++){ if (ac<Array1.length{ Array2[ab]=Array1[ac]; ac=ac+32; }} I have also tried copy array but it only works with whole arrays. Many thanks de Phil.

  • Answer:

    If I understand the question correctly, you're copying exactly 4 elements into array2, correct? So why not: for (int i = 0; i <=4; ++i) { array2[i] = array1[4 + (i * 32)]; } In other words, array2[0] = array1[4]; array2[1] = array1[36]; array2[2] = array1[68]; array2[3] = array1[100];

alf shoemanuer at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.