You need to loop over the rest of the data to find the minimum, not all the data, i.e. j
should start from i+1
, not 0
, otherwise you just end up putting the minimum into the first position, then moving it to the second, then the third and so on, leaving the array completely unsorted, except that the minimum will be at the end.
And using DataManager.getArraySizeExcludingNull(stringArray)
is probably wrong for this problem (judging by the name of the function), as you're treating max
as the last index, not the number of non-null values. You need to simply use stringArray.length
and/or change your function appropriately.