FileDocCategorySizeDatePackage
KeysDemo.javaAPI DocExample1964Tue Dec 12 18:57:36 GMT 2000None

KeysDemo

public class KeysDemo extends Object

Fields Summary
Constructors Summary
Methods Summary
static voiddisplayWords(java.text.CollationKey[] keys)


      for (int i = 0; i < keys.length; i++) {
                System.out.println(keys[i].getSourceString());
      }
   
public static voidmain(java.lang.String[] args)


      Collator enUSCollator = Collator.getInstance(new Locale("en","US"));
  
      String [] words = {
        "peach",
        "apricot",
        "grape",
        "lemon"
      };
 
      CollationKey[] keys = new CollationKey[words.length];
  
      for (int k = 0; k < keys.length; k ++) {
         keys[k] = enUSCollator.getCollationKey(words[k]);
      }
 
      sortArray(keys);
      displayWords(keys);
   
public static voidsortArray(java.text.CollationKey[] keys)


       CollationKey tmp;

       for (int i = 0; i < keys.length; i++) {
          for (int j = i + 1; j < keys.length; j++) {
             // Compare the keys
             if( keys[i].compareTo( keys[j] ) > 0 ) {
                // Swap keys[i] and keys[j] 
                tmp = keys[i];
                keys[i] = keys[j];
                keys[j] = tmp;
             }
          }
       }