0
Output 2 arrays in 1 new array
public class Program { static int[] h1 = {2,3}; static int[] h2 = {4,5}; public static void main(String[] args) { int[][] h3 = {h1, h2}; System.out.println(h3); } } This is the only code that makes sense for me and doesnât end up with errors when iâm trying to output the two strings h1 and h2 together as h3 = {2,3,4,5} But it somehow doesnât work either and outputs nothing, can someone help me make this work?
2 Answers
0
You are making 2D array and holding array reference inside.
To get combined array values in 1D :
Create array of size h1.length + h2.length then copy values into h3 array..
int[] h3 = new int [h1.length+ h2.length];
First copy h1 values next h2.