VIRGIN FOREST OF JAVA
          不要埋頭苦干,要學習,學習,再學習。。。。。
          powered by R.Zeus
          public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneable, Serializable

          public class TreeMap<K,V>
          ??? extends AbstractMap<K,V>
          ??? implements SortedMap<K,V>, Cloneable, java.io.Serializable

          Obviously,TreeMap store elements sorted.But for the chinese word ,the default Comparator don't? do it rightly,so you must write your Comparator .this is an example from web:

          importjava.text.CollationKey;

          import java.text.Collator;

          import java.util.Comparator;

          ?

          /**

          ?*@author www.inspiresky.com

          ?*

          ?*/

          publicclass CollatorComparator implements Comparator {

          Collator collator = Collator.getInstance();

          ?

          publicint compare(Object element1, Object element2) {

          ??? CollationKey key1 = collator.getCollationKey(element1.toString());

          ??? CollationKey key2 = collator.getCollationKey(element2.toString());

          ??? return key1.compareTo(key2);

          }

          }


          ? to use this CollatorComparator ,use TreeMap constructor
          Mothod :

          ?public TreeMap(Comparator<? super K> c) {
          ??????? this.comparator = c;
          ??? }


          posted on 2006-10-30 16:32 R.Zeus 閱讀(334) 評論(0)  編輯  收藏 所屬分類: J2SE
          主站蜘蛛池模板: 长泰县| 雅安市| 竹北市| 普安县| 攀枝花市| 高淳县| 北川| 故城县| 昭平县| 西安市| 焉耆| 凤翔县| 渝中区| 三门县| 唐河县| 保靖县| 惠州市| 乐至县| 建始县| 大方县| 莱阳市| 平邑县| 屏南县| 五原县| 比如县| 江永县| 望都县| 天柱县| 萝北县| 宽城| 钟祥市| 泽普县| 太保市| 磐安县| 内江市| 平乡县| 曲阜市| 罗江县| 县级市| 肇庆市| 云龙县|