java - Creating an algorithm that can sort string/integer arrays -
i trying figure out how make sorting function sort array in descending order.
public void dsort(string field) throws datasetexception { int front = 0; int findex = -1; string[] tosort = new string[50]; (int = 0; < filedata[0].length; i++) { if (field.equalsignorecase(filedata[0][i])) { findex = i; } } if (findex == -1) { throw new datasetexception(); } else { (int k = 0; k < getnumrecords(); k++) { if (filedata[k][findex] != null) { tosort[front] = filedata[k][findex]; front++; } } comparator comparator = collections.reverseorder(); arrays.sort(tosort, comparator); system.out.println(arrays.aslist(tosort)); } } what creates new array taking elements array of arrays, want do. however, output of sort 32, 3, 25, 20, 2, 1000, 1 etc.. these "integers" considered strings, , sorting function supposed able sort words strings. think should trying use comparable, unsure of how implement in situation.
if number, don't want store them string, store them numbers , use numeric sort.
if on other hand, have combination of strings, of numeric, , of alphabetic, i'd recommend using alphanumcomparator, available here
Comments
Post a Comment