Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I properly alphabetize (sort) a list of strings in a language-sensitive manner?

0
Posted

How do I properly alphabetize (sort) a list of strings in a language-sensitive manner?

0

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

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123