Java HashMapºÍTreeMapµÄÅÅÐòÎÊÌâ×ܽá
Map´æ´¢µÄÊÇkey->valueµÄÖµ¶Ô£¬keyµÄÖµÊÇΨһµÄ£¬¶øvalueµÄÖµ¿ÉÒÔÖظ´¡£Í¨³£Ê¹ÓõÄÊÇHashMap»òTreeMap£¬Èç¹û¿¼ÂÇÐÔÄÜ£¬Ê¹ÓÃHashMap¡£TreeMapʹÓúìºÚÊ÷ʵÏÖ£¬±£ÁôÓÐkeyֵ˳ÐòÐÔ£¬»á×Ô¶¯°´ÕÕkeyÖµÅÅÐò¡£
ĬÈÏÊÇ°´ÕÕkeyÖµµÄÉýÐòÅÅÐò£¬keyÖµ±ØÐëʵÏÖ Comparator½Ó¿Ú¡£Èç¹ûÏ£Íû°´ÕÒÒ»¶¨¹æÔòÅÅÐò£¬ÔòÐèÒªÖØж¨Òåcompareº¯Êý¡£
Èç:
TreeMap hm = new TreeMap<String, String>(new Comparator() {
public int compare(Object o1, Object o2) {
//Èç¹ûÓпÕÖµ£¬Ö±½Ó·µ»Ø0
if (o1 == null || o2 == null)
return 0;
return String.valueOf(o1).compareTo(String.valueOf(o2));
}
});
¶ÔÓÚ´¦ÀíÓÐÖÐÎÄÅÅÐòµÄÎÊÌâ
TreeMap hm = new TreeMap<String, String>(new Comparator() {
public int compare(Object o1, Object o2) {
//Èç¹ûÓпÕÖµ£¬Ö±½Ó·µ»Ø0
if (o1 == null || o2 == null)
return 0;
CollationKey ck1 = collator.getCollationKey(String.valueOf(o1));
CollationKey ck2 = collator.getCollationKey(String.valueOf(o2));
return ck1.compareTo(ck2);
}
});
±¸×¢£º CollationKey£ºCollationKey ±íʾ×ñÊØÌض¨ Collator ¶ÔÏó¹æÔòµÄ String¡£
±È½ÏÁ½¸öCollationKey ½«·µ»ØËüÃÇËù±íʾµÄ String µÄÏà¶Ô˳Ðò¡£Ê¹Óà CollationKey À´±È½Ï String ͨ³£±ÈʹÓà Collator.compare ¸ü¿ì¡£Òò´Ë£¬µ±±ØÐë¶à´Î±È½Ï String ʱ £¨ÀýÈ磬¶ÔÒ»¸ö String Áбí½øÐÐÅÅÐò£©£¬Ê¹Óà CollationKey »á¸ü¸ßЧ¡£
Èç¹ûÏë°´ÕÕvalueÅÅÐò»òÕßÊǶÔHashMapÖеÄkey»òvalueÅÅÐòÔò¿ÉÒÔÈçÏ£º
List<Map.Entry<String,Integer>> list = new ArrayList<Map.Entry<String,Integer>>(m.entrySet());
Collections.sort(list,new Comparator<Map.Entry<String,Integer>>(){
public int compare(Map.Entry<String,Integer> o1, Map.Entry<String,Integer> o2){
return o2.getValue()-o1.getValue();
}
});&
Ïà¹ØÎĵµ£º
Java NIO APIÏê½â
ÔÚJDK
1.4ÒÔÇ°£¬JavaµÄIO²Ù×÷¼¯ÖÐÔÚjava.ioÕâ¸ö°üÖУ¬ÊÇ»ùÓÚÁ÷µÄ×èÈû£¨blocking£©API¡£¶ÔÓÚ´ó¶àÊýÓ¦ÓÃÀ´Ëµ£¬ÕâÑùµÄAPIʹÓúܷ½
±ã£¬È»¶ø£¬Ò»Ð©¶ÔÐÔÄÜÒªÇó½Ï¸ßµÄÓ¦Óã¬ÓÈÆäÊÇ·þÎñ¶ËÓ¦Óã¬ÍùÍùÐèÒªÒ»¸ö¸üΪÓÐЧµÄ·½Ê½À´´¦ÀíIO¡£´ÓJDK 1.4Æð£¬NIO
API×÷Ϊһ¸ö»ùÓÚ»º³åÇø£¬²¢ÄÜÌṩ·Ç×èÈû(non-blo ......
java exception ½â¾ö·½°¸ - ÎÒµÄÒì³£Íø|Òì³£|exception 791 - java.lang.NoSuchMethodError 792 - RuntimeException 793 - org.hibernate.exception.SQLGrammarException 794 - Internal Error 795 - ×Ô¶¨ÒåÒì³£ 796 - org.dom4j.DocumentException 797 - java.net.SocketException 798 - Exception¶ÔÏó 799 - SQLE ......
Java×Ö·û´®Àà(java.lang.String)ÊÇJavaÖÐʹÓÃ×î¶àµÄÀ࣬ҲÊÇ×îΪÌØÊâµÄÒ»¸öÀ࣬ºÜ¶àʱºò£¬ÎÒÃǶÔËü¼ÈÊìϤÓÖÄ°Éú¡£
Ò»¡¢´Ó¸ù±¾ÉÏÈÏʶjava.lang.StringÀàºÍString³Ø
Ê×ÏÈ£¬ÎÒ½¨ÒéÏÈ¿´¿´StringÀàµÄÔ´ÂëʵÏÖ£¬ÕâÊÇ´Ó±¾ÖÊÉÏÈÏʶStringÀàµÄ¸ù±¾³ö·¢µã¡£´ÓÖпÉÒÔ¿´µ½£º
1¡¢StringÀàÊÇfinalµÄ£¬²»¿É±»¼Ì³Ð¡£publ ......
±ÊÊÔµÄʱºòÏë²»ÆðÀ´ÔõôдÁË¡£Áô¸ö´úÂë×÷¼ÍÄî
package common;
import java.io.*;
import java.util.ArrayList;
public class IOTest {
public static void main (String args[]) {
ReadDate();
WriteDate();
}
/**
* ¶ÁÈ¡Êý¾Ý
*/
public static void ReadDate() {
......
FlexÖÐXMLSocketÓëJavaÖÐSocketͨÐÅ£¬Óöµ½µÄÎÊÌâÊÇ£¬JavaÖеÄsocketÄܹ»½ÓÊܵ½XMLSocket´«ÊäµÄÊý¾Ý£¬µ«ÊÇFlex²¢²»ÄܽÓÊܵ½´ÓJava·þÎñÆ÷´«ÊäµÄÊý¾Ý£¬´ÓÍøÉÏËÑÁ˺öà×ÊÁÏ£¬ÖÕÓÚÕÒµ½ÁËÔÒò£¬ÔÀ´XMLSocket ½ÓÊÕµ½·þÎñ¶ËÏ·¢µÄÊý¾Ýʱ£¬½«Á¬Ðø·ÅÓÚ½ÓÊÕ»º³åÇø£¬Ö±µ½½ÓÊÕµ½ "\0" ×Ö½Ú£¨×Ö½ÚÄÚÈÝΪ ASCII Öµ 0£©£¬²ÅÈÏΪ½ÓÊÕÍê³É£¬² ......