Concatenating two int[]

后端 未结 3 894
野的像风
野的像风 2020-12-15 18:02

There are easy solutions for concatenating two String[] or Integer[] in java by Streams. Since int[] is frequently used.

3条回答
  •  死守一世寂寞
    2020-12-15 18:12

    Use for loops, to avoid using toArray().

    int[] e = new int[c.length+d.length];
    int eIndex = 0;
    for (int index = 0; index < c.length; index++){
        e[eIndex] = c[index];
        eIndex++;
    }
    for (int index = 0; index < d.length; index++){
        e[eIndex] = d[index];
        eIndex++;
    }
    

提交回复
热议问题