java - RuleBasedCollator not sorting as expected with special character (dash) in quotes -


i dashes come after spaces. it's not working. dashes being ignored though enclosed in quotes. why?

text-argument: text-argument sequence of characters, excluding special characters (that is, common whitespace characters [0009-000d, 0020] , rule syntax characters [0021-002f, 003a-0040, 005b-0060, 007b-007e]). if characters desired, can put them in single quotes (e.g. ampersand => '&'). note unquoted white space characters ignored; e.g. b c treated bc.

public static void sortfile() throws ioexception, parseexception {     bufferedreader br = new bufferedreader(             new inputstreamreader(new fileinputstream("c:\\def.txt"),                     "cp1252"));           rulebasedcollator mycollator = (rulebasedcollator) collator.getinstance(locale.us);      list<string> lines = new arraylist<string>();     string line = null;     while ((line = br.readline()) != null) {                     line = line.replace(" ", "' '");         line = line.replace("\t", "'\t'");         line = line.replace("-", "'-'");         lines.add(line);     }     br.close();      collections.sort(lines, mycollator);      bufferedwriter out = new bufferedwriter(new outputstreamwriter(             new fileoutputstream("c:\\defsorted.txt"), "cp1252"         ));           (string line1 : lines) {                         line1 = line1.replace("' '", " ");         line1 = line1.replace("'\t'", "\t");         line1 = line1.replace("'-'", "-");         out.write(line1 + "\r\n");     }     out.close(); } 

input file:

bottom bottom antiquark bottom dollar bottom-dweller bottom-dwelling bottome bottom feeder bottomfeeder bottom-feeder bottom feeders bottomfeeders bottom feeding 

sorted file:

bottom bottom antiquark bottom dollar bottom-dweller bottom-dwelling bottom feeder bottom-feeder bottom feeders bottom feeding bottome bottomfeeder bottomfeeders 

expected result:

bottom bottom antiquark bottom dollar bottom feeder bottom feeders bottom feeding bottom-dweller bottom-dwelling bottom-feeder bottome bottomfeeder bottomfeeders 


Comments