[Solved] unexpected results: null next to the string [closed]


Basically what is happening is you are creating an array of Strings.
And you are only initialising the first element of the array to “”
sArr[0] = “”;

That is why every other element but the first element has a null preceding it.

So this statement sArr[test] += c; is going to add a null value for all non initialised strings in your array of Strings.

I would suggest instead of sArr[0] = “”; you can do this
Arrays.fill(sArr , “”)
It initialises all values of the strings in the array to “”

Arrays is a class found under utils which you are importing.

solved unexpected results: null next to the string [closed]