VIRGIN FOREST OF JAVA
          不要埋頭苦干,要學(xué)習(xí),學(xué)習(xí),再學(xué)習(xí)。。。。。
          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
          主站蜘蛛池模板: 射阳县| 乌苏市| 安顺市| 宝鸡市| 江城| 柘城县| 南开区| 光山县| 增城市| 资阳市| 大竹县| 公安县| 建湖县| 苍南县| 霞浦县| 金湖县| 延庆县| 蓝田县| 象州县| 沂水县| 洞头县| 祁连县| 汨罗市| 吴江市| 小金县| 延寿县| 宜良县| 汾西县| 林芝县| 佳木斯市| 景宁| 宣威市| 甘孜| 白城市| 济阳县| 十堰市| 奉节县| 思南县| 泸溪县| 青神县| 呈贡县|