There is no automatic conversion from array of primitive type to array of their boxed reference types or vise versa. You have to iterate for each data.
Converting List<Long> to long[]
1
2
3
4
5
6
7
| List input = getSomeLongs(); // Assume some values
long[] output = new long[input.size()];
int index = 0;
for(Long val : input) {
indexess[index] = val;
index++;
} |
List input = getSomeLongs(); // Assume some values
long[] output = new long[input.size()];
int index = 0;
for(Long val : input) {
indexess[index] = val;
index++;
}
Converting long[] to List<Long>
1
2
3
4
5
| long[] input = getSomeLongs(); // Assume some values
List output = new ArrayList();
for(long val : input){
lst.add(val);
} |
long[] input = getSomeLongs(); // Assume some values
List output = new ArrayList();
for(long val : input){
lst.add(val);
}
Editorial Team
We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.