How do I properly alphabetize (sort) a list of strings in a language-sensitive manner?
Location: http://www.jguru.com/faq/view.jsp?EID=974 Created: Nov 14, 1999 Modified: 2000-01-15 15:41:30.423 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) This is actually outside the scope of the Collections Framework. Instead, it is part of the java.text package with the Collator and CollationKey classes. The following example demonstrates this capability: import java.text.*; import java.util.*; public class CollatorTest { public static void main(String args[]) { Collator collator = Collator.getInstance(); CollationKey key1 = collator.getCollationKey(“Tom”); CollationKey key2 = collator.getCollationKey(“tom”); CollationKey key3 = collator.getCollationKey(“thom”); CollationKey key4 = collator.getCollationKey(“Thom”); CollationKey key5 = collator.getCollationKey(“Thomas”); Set set = new TreeSet(); set.add(key1); set.add(key2); set.add(key3); set.add(key4); set.add(key5); printCollection(set); } static private void printCollection( Collection collection) { boolean f