Sorting standards with alphanumerical data (and special characters) with case insensivity in Java -
i have list of characters sequences. need sort them in order feels natural. i'm coding in java. initial thought use collections.sort()
. think method follows ascii order separates lower case , upper case text. that's not natural flow.
trying define "natural sorting" made quick search , found niso tr03-1999 standard seems address issue.
so guess need way sort using algorithm defined in standard. there function in java ? or need implement myself ?
is there i'm overlooking here ?
did had similar issue in past ? how did deal ?
here's code sample testing collections.sort():
list<string> list = new arraylist<string>(); list.add("z"); list.add("a"); list.add("z"); list.add("a"); list.add("z 1"); list.add("a 1"); list.add("z 1"); list.add("a 1"); list.add(" space"); list.add("!"); list.add("."); list.add(";"); list.add("\\"); list.add("/"); list.add("+"); list.add("1"); list.add("2"); list.add("10"); list.add("1abc"); list.add("2abc"); list.add("10abc"); collections.sort(list); (string string : list) system.out.println(string);
take @ collator. here docs: https://docs.oracle.com/javase/8/docs/api/java/text/collator.html
Comments
Post a Comment