We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
It does work on strings. But in our case, we're creating the names array of max-size, and adding only a few string elements to it. Arrays.sort() does not work when there are unassigned elements in the array - Null Pointer Exception.
The workaround will be to use a List, and then Collections.sort() on it.
Or to create a smaller array, once you know how many elements you need, and then copy from the larger array to the smaller one. Now run the sort on the smaller (all elements assigned) array.
Day 28: RegEx, Patterns, and Intro to Databases
You are viewing a single comment's thread. Return to all comments →
It does work on strings. But in our case, we're creating the names array of max-size, and adding only a few string elements to it. Arrays.sort() does not work when there are unassigned elements in the array - Null Pointer Exception.
The workaround will be to use a List, and then Collections.sort() on it.
Or to create a smaller array, once you know how many elements you need, and then copy from the larger array to the smaller one. Now run the sort on the smaller (all elements assigned) array.
Hope this helps!