this is a rather basic java question
I have an array containing String that i want to sort using java.util.Arrays.sort
when i write
String[] myArray = {'A','B','C'}; java.util.Arrays.sort(myArray);
it gets sorted correctly
however when i have
String[] myArray = new String[10]; myArray[0] = 'A'; myArray[1] = 'B'; myArray[2] = 'C'; java.util.Arrays.sort(myArray);
sort throws a nullreferenceexception
i’m pretty sure its something really dumb i just dont get right now. I have to new the String, because hardcoding default values doesnt get anyone, anywhere.
When you initialize the second array, you only initialize the first three elements. The other elements are initialized to null and thus can’t be sorted.