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ÖеĴ«µÝ¶¼ÊÇÖµ´«µÝÂð£¿ÓÐûÓÐÒýÓô«µÝÄØ£¿
ÔڻشðÕâÁ½¸öÎÊÌâÇ°£¬ÈÃÎÒÃÇÊ×ÏÈÀ´¿´Ò»¶Î´úÂ룺
Java´úÂë
public class ParamTest {
// ³õʼֵΪ0
protected int num = 0;
// Ϊ·½·¨²ÎÊýÖØи³Öµ
public void change(int i) {
i = 5;
}
// Ϊ·½·¨²ÎÊýÖØи³Öµ
public void change(ParamTest t) {
P ......
JavaÀïÃæµÄdnd;
½çÃæ±à³ÌÀïÃæÄÜÊìÁ·µÄÔËÓõÄÈ˲»¶à,¶ø¶ÔJavaÖеÄÍÏק֪¸ùÖªµ×µÄÈ˾͸üÉÙÁËÎÒµÄһƪ ÎÄÕÂ-- JavaÖеÄDrag and DropÏê½âÓë´úÂëʾÀý ÀïÃæÓÐÏêϸ½éÉÜ.
java.awt.MouseInfo, java.awt.PointerInfo;
ÎÒÔø¾ÏëµÃµ½Êó±êÔÚÆÁÄ»Éϵľø¶ÔλÖÃ,ÎÒÊÔ¹ýͨ¹ýÔÚMouseListenerÀïÃæµÃµ½Êó±êÔÚÒ»¸ö¿Ø¼þÀïÃæµÄÏච......
ͻ񻣼
±¾ÎÄÕë¶Ôjava³õѧÕß»òÕßannotation³õ´ÎʹÓÃÕßÈ«ÃæµØ˵Ã÷ÁËannotationµÄʹÓ÷½·¨¡¢¶¨Ò巽ʽ¡¢·ÖÀà¡£³õѧÕß¿ÉÒÔͨ¹ýÒÔÉϵÄ˵Ã÷ÖÆ×÷¼òµ¥µÄannotation³ÌÐò£¬µ«ÊǶÔÓÚһЩ¸ß¼¶µÄannotationÓ¦Óã¨ÀýÈçʹÓÃ×Ô¶¨ÒåannotationÉú³ÉjavabeanÓ³ÉäxmlÎļþ£©»¹ÐèÒª½øÒ»²½µÄÑо¿ºÍ̽ÌÖ¡£Éæ¼°µ½ÉîÈëannotationµÄÄÚÈÝ£¬×÷Õß½«ÔÚºóÎÄ¡ ......
ÍøÉÏתÌùµÄJavaÕýÔòºÜÈÃÈËʧÍû£¬Ò»ÆªJavaScriptÕýÔò¼¯Â¼±»ºÜ¶à²»¸ºÔðÈεÄÈËתÀ´×ªÈ¥£¬²¢´òÉÏJavaÕýÔòµÄ±êÌ⣬º¹£¬ÕæÊÇÀÃÈËÒ»¶Ñ¡£
// urlÕýÔò
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegularExpressionTest {
public static void main(String[] args) {
Pa ......
Java json lib
¸ù¾Ýhttp://www.javaeye.com/topic/561368̸µ½µÄÒ»¸öjacksonµÄjsonÐòÁл¯¹¤¾ßÐÔÄܱÈjson-libµÈÒªºÃ
ÎÞÂÛÊÇÔڵͲ¢·¢»¹ÊǸ߲¢·¢µÄÇé¿öÏ£¬Ê±¼äÐÔÄÜÉÏ£¬jacksonʹÓÃÖØÓÃObjectMapper·½Ê½´ó´óÓÅÓÚʹÓÃjson-lib·½Ê½£¬ÉõÓÚjacksonʹÓ÷ÇÖØÓÃObjectMapper·½Ê½Ò²ÂÔÓÅÓÚjson-lib·½Ê½¡£ÁíÍâÒ²¿ÉÒÔ¿´³ö£¬jacksonÔÚÖØÓà ......