public static void main(String[] args) {
char [][] charArr =
{ {'a','b','c'},
{'d','e','f'},
{'g','h','i'}
};
String [] stringA = charToString(charArr);
for (int i = 0; i < stringA.length; i++)
{
System.out.println(stringA[i]);
}
}
public static String [] charToString(char [][] array)
{
String [] stringArr = new String [array.length];
for (int i = 0; i < array.length; i++)
{
stringArr[i] += "";
for (int j = 0; j < array[i].length; j++)
{
stringArr[i] += array[i][j];
}
}
return stringArr;
Currently I am getting an output of:
nullabc
nulldef
nullghi
I am trying to concatenate each column of the 2d array charArr into a string and into each element of the 1d array called stringArr. I'm not sure where null is coming from though or what I'm doing wrong...
Appreciate the help!
return Arrays.stream(array).map(String::new).toArray(String[]::new)