I am not able to assign a String variable to a String Array.
My code is :
//Declaring a String array
public String [] fileWrite = new String [10];
//assigning a variable
String value = String.valueOf(aChar1);
fileWrite[0] = value;
But when I try to print the array, it gives null. I checked the value of variable value but that is ok. I cant understand the reason of array being null.
Firstly, you need to know that “printing an array” in java is somewhat “broken”: You need to use
Arrays.toString(array)to print an array (you can’t rely onarray.toString()– it isn’t useful).Try this code:
Output: