Answers for "Concatenate two arrays"

1

Concatenate two arrays

Array -- Concatenate two arrays
Write a return method that can concatenate two arrays
 
Solution:
public static int[] concatTwoArrays(int[] arr1 , int[] arr2) {
    int[] result = new int[arr1.length + arr2.length];
    int i = 0;
    for(int each: arr1) {
    result[i] = each;
    i++;
    }  
    for(int each: arr2) {
    result[i] =each;
    i++;
    }
    return result;
    }
Posted by: Guest on September-29-2021
15

javascript concat two arrays

//ES6
const array3 = [...array1, ...array2];
Posted by: Guest on July-03-2020
0

how to concatenate two arrays

int[] z = x.Concat(y).ToArray();
Posted by: Guest on June-14-2021
0

concatenate two array

#include <stdio.h>

int main() {
   int array[10];
   int even[5] = {0, 2, 4, 6, 8};
   int odd[5]  = {1, 3, 5, 7, 9};
   
   int loop, index, e_len, o_len;
   
   e_len = o_len = 5;
   
   index = 0;
 
   for(loop = 0; loop < e_len; loop++) {
      array[index] = even[loop];
      index++;
   }
 
   for(loop = 0; loop < o_len; loop++) {
      array[index] = odd[loop];
      index++;
   }

   printf("\nEven -> ");
   
   for(loop = 0; loop < e_len; loop++)
      printf(" %d", even[loop]);
   
   printf("\nOdd  -> ");
   
   for(loop = 0; loop < o_len; loop++)
      printf(" %d", odd[loop]);

   printf("\nConcat -> ");
   
   for(loop = 0; loop < 10; loop++)
      printf(" %d", array[loop]);

   return 0;
}
Posted by: Guest on September-14-2021
0

concat two arrays

public static void main(String[] args) {

       String[] arr3 = {"A", "B", "C","Z","N"};
       String[] arr4 = {"D", "E", "F","G","U"};
ArrayList<String> list1 = new ArrayList<>();  
//  [A, B, C, Z, N, D, E, F, G, U]

       for( String each: arr3 ){
           list1.add( each );
       }
       for(String each1 : arr4  ){
           list1.add(each1);
       }
System.out.println(list1); // [A, B, C, Z, N, D, E, F, G, U]
Posted by: Guest on June-09-2021
0

how to concatenate two arrays

var z = new int[x.Length + y.Length];
x.CopyTo(z, 0);
y.CopyTo(z, x.Length);
Posted by: Guest on June-14-2021

Code answers related to "Concatenate two arrays"

Browse Popular Code Answers by Language