Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

JAVA ComparatorºÍComparableÔÚÅÅÐòÖеÄÓ¦ÓÃ

ComparatorºÍComparableÔÚÅÅÐòÖеÄÓ¦ÓÃ
µ±ÐèÒªÅÅÐòµÄ¼¯ºÏ»òÊý×é²»Êǵ¥´¿µÄÊý×ÖÐÍʱ£¬Í¨³£¿ÉÒÔʹÓÃComparator»òComparable£¬ÒÔ¼òµ¥µÄ·½Ê½ÊµÏÖ¶ÔÏóÅÅÐò»ò×Ô¶¨ÒåÅÅÐò¡£
Ò»¡¢Comparator
Ç¿ÐжÔij¸ö¶ÔÏócollection½øÐÐÕûÌåÅÅÐòµÄ±È½Ïº¯Êý£¬¿ÉÒÔ½«Comparator´«µÝ¸øCollections.sort»òArrays.sort¡£
½Ó¿Ú·½·¨£º
  /**
   * @return o1СÓÚ¡¢µÈÓÚ»ò´óÓÚo2£¬·Ö±ð·µ»Ø¸ºÕûÊý¡¢Áã»òÕýÕûÊý¡£
   */
  int compare(Object o1, Object o2);
°¸Àý£º
import java.util.Arrays;
import java.util.Comparator;
public class SampleComparator implements Comparator {
  public int compare(Object o1, Object o2) {
    return toInt(o1) - toInt(o2);
  }
  private int toInt(Object o) {
    String str = (String) o;
    str = str.replaceAll("Ò»", "1");
    str = str.replaceAll("¶þ", "2");
    str = str.replaceAll("Èý", "3");
    // 
    return Integer.parseInt(str);
  }
  /**
   * ²âÊÔ·½·¨
   */
  public static void main(String[] args) {
    String[] array = new String[] { "Ò»¶þ", "Èý", "¶þ" };
    Arrays.sort(array, new SampleComparator());
    for (int i = 0; i < array.length; i++) {
      System.out.println(array[i]);
    }
  }
}
 ¶þ¡¢Comparable
Ç¿ÐжÔʵÏÖËüµÄÿ¸öÀàµÄ¶ÔÏó½øÐÐÕûÌåÅÅÐò£¬ÊµÏִ˽ӿڵĶÔÏóÁÐ±í£¨ºÍÊý×飩¿ÉÒÔͨ¹ýCollections.sort»òArrays.sort½øÐÐ×Ô¶¯ÅÅÐò¡£
½Ó


Ïà¹ØÎĵµ£º

javaÖеÄÖµ´«µÝºÍ"ÒýÓô«µÝ"

Öµ´«µÝ£º·½·¨µ÷ÓÃʱ£¬Êµ¼Ê²ÎÊý°ÑËüµÄÖµ´«µÝ¸ø¶ÔÓ¦µÄÐÎʽ²ÎÊý£¬·½·¨Ö´ÐÐÖÐÐÎʽ²ÎÊýÖµµÄ¸Ä±ä²»Ó°Ïìʵ¼Ê²Î ÊýµÄÖµ¡£
"ÒýÓô«µÝ"£ºÒ²³ÆÎª´«µØÖ·¡£·½·¨µ÷ÓÃʱ£¬Êµ¼Ê²ÎÊýµÄÒýÓÃ(µØÖ·£¬¶ø²»ÊDzÎÊýµÄÖµ)±»´«µÝ¸ø·½·¨ÖÐÏà¶ÔÓ¦µÄÐÎʽ²ÎÊý£¬ÔÚ·½·¨Ö´ÐÐÖУ¬¶ÔÐÎʽ²ÎÊýµÄ²Ù×÷ʵ¼ÊÉϾÍÊǶÔʵ¼Ê²ÎÊýµÄ²Ù×÷£¬·½·¨Ö´ÐÐÖÐÐÎʽ²ÎÊýÖµµÄ¸Ä ......

JAVA»ñȡϵͳÐÅÏ¢

Properties props=System.getProperties(); //ϵͳÊôÐÔ
System.out.println("JavaµÄÔËÐл·¾³°æ±¾£º"+props.getProperty("java.version"));
System.out.println("JavaµÄÔËÐл·¾³¹©Ó¦ÉÌ£º"+props.getProperty("java.vendor"));
System.out.println("Java¹©Ó¦É̵ÄURL£º"+props.getProperty("java.vendor.url"));
Syste ......

Java AnnotationÈëÃÅ

ͻ񻣼
±¾ÎÄÕë¶Ôjava³õѧÕß»òÕßannotation³õ´ÎʹÓÃÕßÈ«ÃæµØËµÃ÷ÁËannotationµÄʹÓ÷½·¨¡¢¶¨Ò巽ʽ¡¢·ÖÀà¡£³õѧÕß¿ÉÒÔͨ¹ýÒÔÉϵÄ˵Ã÷ÖÆ×÷¼òµ¥µÄannotation³ÌÐò£¬µ«ÊǶÔÓÚһЩ¸ß¼¶µÄannotationÓ¦Óã¨ÀýÈçʹÓÃ×Ô¶¨ÒåannotationÉú³ÉjavabeanÓ³ÉäxmlÎļþ£©»¹ÐèÒª½øÒ»²½µÄÑо¿ºÍ̽ÌÖ¡£Éæ¼°µ½ÉîÈëannotationµÄÄÚÈÝ£¬×÷Õß½«ÔÚºóÎÄ¡ ......

java³£Óðü

1¡¢java.lang°ü£ºjavaµÄºËÐÄÀà¿â£¬°üº¬ÁËÔËÐÐjava³ÌÐò±Ø²»¿ÉÉÙµÄϵͳÀ࣬Èç»ù±¾Êý¾ÝÀàÐÍ¡¢»ù±¾Êýѧº¯Êý¡¢×Ö·û´®´¦Àí¡¢Ï̡߳¢Òì³£´¦ÀíÀàµÈ£¬ÏµÍ³È±Ê¡¼ÓÔØÕâ¸ö°ü
2¡¢java.io°ü£ºjavaÓïÑԵıê×¼ÊäÈë/Êä³öÀà¿â£¬Èç»ù±¾ÊäÈë/Êä³öÁ÷¡¢ÎļþÊäÈë/Êä³ö¡¢¹ýÂËÊäÈë/Êä³öÁ÷µÈµÈ
3¡¢java.util°ü£º°üº¬Èç´¦Àíʱ¼äµÄdateÀ࣬´¦Àí±ä³ÉÊý ......

javaÖÐÖ´ÐÐÍⲿÃüÁî

ÔÚjavaÖпÉÒÔͨ¹ýRuntime.getRuntime().exec(cmd)À´Ö´ÐÐÍⲿÃüÁÎұȽϳ£ÓõÄÊǵ÷ÓÃshell½Å±¾À´Íê³ÉijЩ¹¤×÷£¬Ò²¿ÉÒÔÖ±½ÓÖ´ÐÐÒ»¸öos µÄÃüÁ±È½Ïµ÷ÓÃimagemagickÀ´Íê³ÉͼƬµÄһЩ²Ù×÷£¬ÆäÖÐÐèҪעÒâµÄÓÐÁ½µã£¬1ÊÇ×îºÃ´øÉÏÃüÁîµÄÍêÕû·¾¶,·ñÔòÃüÁî¿ÉÄܲ»»á±»Ö´ÐУ¬¶øÇÒҲûÓÐÈκα¨´íµÄÐÅÏ¢Êä³ö£¬2ÌØ±ðҪעÒâ¿Õ¸ñ£¬±ÈÈçÎÄ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ