java ±È½ÏÆ÷µÄʹÓÃ
¶ÔÓÚÒ»¸öʵÏÖÁËComparable½Ó¿ÚµÄ¶ÔÏ󣬸ýӿÚÖ»ÄÜʵÏÖÒ»´Î¡£Èç¹ûÔÚÒ»¸ö¼¯ºÏÀïÃæÐèҪʹÓÃidÅÅÐò£¬¶øÔÚÁíÍâÒ»¸ö¼¯ºÏÀïÐèÒª°´Ãû×ÖÅÅÐòÕâʱ¾ÍÐèÒªÔÚÕâ¸ö¼¯ºÏÀïÃæÖ¸¶¨±È½ÏÆ÷¡£
Comparable½Ó¿ÚÉùÃ÷ÁËcompareTo(Object o)·½·¨
Comparator ½Ó¿ÚÉùÃ÷ÁËcompare(Object o1,Object o2)·½·¨
eg:
µÚÒ»¸öÊ÷¼¯ÊÇ°´ÕÕ¶ÔÏóĬÈϵÄidÅÅÐò£¬µÚ¶þ¸öÊ÷¼¯ÓÉÖ¸¶¨µÄ¹¹ÔìÆ÷°´ÕÕname ÅÅÐò
public class Employee implements Comparable<Employee>{
private int id;
private String name;
public Employee(int id, String name){
this.id = id;
this.name = name;
}
public boolean equals(Object o){
if (o == null ){
return false;
}
if (this == o){
return true;
}
if(!(o instanceof Employee)){
return false;
}
Employee employee = (Employee)o;
return (this.id == employee.id) && (this.name.equals(employee.name));
}
public int hashCode(){
int result = 17;
result = 37 * result + id;
result = 37 * result + name.hashCode();
return result;
}
public String toString(){
return "id:"+id+",name:"+name+"";
}
public int compareTo(Employee employee){
//ÉýÐò
return this.id - employee.id;
//½µÐò
//return employee.id - this.id;
}
public String getName() {
return name;
}
}
/*******************************************************************/
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.Comparator;
public class TreeSetTest {
public static void main(String []args){
//ʹÓõÄÊÇʵÏÖÁËCompable ½Ó¿Ú¶ÔÏóĬÈϵÄÅÅÐò·½Ê½£¬°´idÉýÐòÅÅÐò
SortedSet<Employee> treeSet = new TreeSet&
Ïà¹ØÎĵµ£º
1. Òì³£»úÖÆ
Òì³£»úÖÆÊÇÖ¸µ±³ÌÐò³öÏÖ´íÎóºó£¬³ÌÐòÈçºÎ´¦Àí¡£¾ßÌåÀ´Ëµ£¬Òì³£»úÖÆÌṩÁ˳ÌÐòÍ˳öµÄ°²È«Í¨µÀ¡£µ±³öÏÖ´íÎóºó£¬³ÌÐòÖ´ÐеÄÁ÷³Ì·¢Éú¸Ä±ä£¬³ÌÐòµÄ¿ØÖÆȨתÒƵ½Òì³£´¦ÀíÆ÷¡£
´«Í³µÄ´¦ÀíÒì³£µÄ°ì·¨ÊÇ£¬º¯Êý·µ»ØÒ»¸öÌØÊâµÄ½á¹ûÀ´±íʾ³öÏÖÒì³££¨Í ......
1¡¢Óï·¨£º±ØÐë±È½ÏÊìϤ£¬ÔÚд´úÂëµÄʱºòIDEµÄ±à¼Æ÷¶ÔijһÐб¨´íÓ¦¸ÃÄܹ»¸ù¾Ý±¨´íÐÅÏ¢ÖªµÀÊÇʲôÑùµÄÓï·¨´íÎó²¢ÇÒÖªµÀÈκÎÐÞÕý¡£
2¡¢ÃüÁ±ØÐëÊìϤJDK´øµÄһЩ³£ÓÃÃüÁî¼°Æä³£ÓÃÑ¡ÏÃüÁîÖÁÉÙÐèÒªÊìϤ£ºappletviewer¡¢ HtmlConverter¡¢jar¡¢ java¡¢javac¡¢javadoc¡¢javap¡¢javaw¡¢ ......
java jce¶ÔaesËã·¨ÓкܺõÄÖ§³Ö£¬µ«ÊÇĬÈÏ°²×°µÄJDK»òÕßJREÊDz»ÄÜÖ§³Öaes192bitÃÜÔ¿ºÍaes256bitÃÜÔ¿Á½ÖÖËã·¨µÄ£¬ÐèÒªµ½sun¹Ù·½ÏÂÔØJava(TM) Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files£¬ÒÔÏÂÊÇjce unilimited strength jurisdiction policy files 6µÄ¹Ù·½ ......
ѧϰJavaÖµ´«µÝ·½·¨-Î人±±´óÇàÄñ
¡¡¡¡Öµ´«µÝÊÇÔÚÒ»¸öº¯ÊýÖУ¬µ÷ÓÃÁíÍâÒ»¸öº¯Êý£¬ÆäÖк¬ÓвÎÊý´«µÝµÄÇé¿ö¡£ÍùÍùÖµ´«µÝ¾ÍÊÇ°ÑÊý¾Ý´«µÝµ½ÁíÍâÒ»¸öº¯ÊýÖнøÐнøÒ»²½´¦Àí£¬ÒÔ¸üÇå³þµØÏÔʾº¯ÊýµÄ±í´ïÒâ˼¡£ÔÚº¯Êýµ÷ÓõÄʱºò»áÓÐÊý¾Ý´«µÝ£¬Í¬ÑùÒª¿¼ÂÇÐβκÍʵ²ÎµÄÎÊÌ⣬ÈçÏÂÃæµÄÒ»¸ö³ÌÐò£º
¡¡¡¡on error resume next ShockMode ......
1. Õ»(stack)Óë¶Ñ(heap)¶¼ÊÇJavaÓÃÀ´ÔÚRamÖдæ·ÅÊý¾ÝµÄµØ·½¡£ÓëC++²»Í¬£¬Java×Ô¶¯¹ÜÀíÕ»ºÍ¶Ñ£¬³ÌÐòÔ±²»ÄÜÖ±½ÓµØÉèÖÃÕ»»ò¶Ñ¡£
2. Õ»µÄÓÅÊÆÊÇ£¬´æÈ¡ËٶȱȶÑÒª¿ì£¬½ö´ÎÓÚÖ±½ÓλÓÚCPUÖеļĴæÆ÷¡£µ«È±µãÊÇ£¬´æÔÚÕ»ÖеÄÊý¾Ý´óСÓëÉú´æÆÚ±ØÐëÊÇÈ·¶¨µÄ£¬È±·¦Áé»îÐÔ¡£ÁíÍ⣬ջÊý¾Ý¿ÉÒÔ¹²Ïí£¬Ïê¼ûµÚ3µã¡£¶ÑµÄÓÅÊÆÊÇ¿ÉÒÔ¶¯Ì¬µØ·ÖÅä ......