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
Related Q & A:
- Is it possible to migrate Oracle SOA BPEL instances from one environment to another with history?Best solution by Server Fault
- How to insert data from one table to another?Best solution by Stack Overflow
- How to see if one string contains another string?Best solution by Stack Overflow
- How to pass an ArrayList from one class to another?Best solution by stackoverflow.com
- How can I move bookmarks from one email to another one?Best solution by pcworld.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.