java ¼¯ºÏÀà
¼¯ºÏCollection½Ó¿Ú
--Collection ÊÇÈκζÔÏó×飬ԪËظ÷×Ô¶ÀÁ¢£¬Í¨³£ÓµÓÐÏàͬµÄÌ×ÓùæÔò¡£Set ListÓÉËüÅÉÉú¡£
»ù±¾²Ù×÷ Ôö¼ÓÔªËØadd(Object obj); addAll(Collection c);
ɾ³ýÔªËØ remove(Object obj); removeAll(Collection c);
Çó½»¼¯ retainAll(Collection c);
ɾ³ýÔªËØ remove(Object obj); removeAll(Collection c);
Çó½»¼¯ retainAll(Collection c);
·ÃÎÊ/±éÀú¼¯ºÏÔªËصĺð취ÊÇʹÓÃIterator½Ó¿Ú(µü´úÆ÷ÓÃÓÚÈ¡´úEnumeration)
Public interface Iterator{
Public Boolean hasNext(};
¡¡ Public Object next(};
¡¡Public void remove(};
}
Ò»¡¢set
ÎÞÖظ´¡¢ÎÞÐò
HashSet-»ùÓÚÉ¢ÁбíµÄ¼¯£¬¼Ó½øÉ¢ÁбíµÄÔªËØҪʵÏÖhashCode()·½·¨ÒÔÅжÏÊÇ·ñΪͬһ¸ö¶ÔÏó£¬ÎÞ˳Ðò¡¢ÎÞÖظ´¡£
LinkedHashSet-ÔÚHashSetÖмÓÈëÁËÁ´±íÊý¾Ý½á¹¹£¬ÓÐ˳Ðò
TreeSet-¿ÉÒÔÅÅÐò£¬ÐèҪʵÏÖComparable½Ó¿Ú£¬²¢ÊµÏÖÆäcompareTo()·½·¨£¬ÒÔÅÅÐò¡£
¶þ¡¢List
ÓÐÖظ´¡¢ÓÐÐò
ArrayList(Êý×é±í)- ÓÐÖظ´¡¢ÓÐ˳Ðò¡£ÀàËÆÓÚVector£¬¶¼ÓÃÓÚËõ·ÅÊý×éά»¤¼¯ºÏ¡£Çø±ð£º
Ò».ͬ²½ÐÔ:VectorÊÇḬ̈߳²È«µÄ£¬Ò²¾ÍÊÇ˵ÊÇͬ²½µÄ£¬¶øArrayListÊÇÏß³ÌÐò²»°²È«µÄ£¬²»ÊÇͬ²½µÄ
¶þ.Êý¾ÝÔö³¤:µ±ÐèÒªÔö³¤Ê±,VectorĬÈÏÔö³¤ÎªÔÀ´Ò»Å࣬¶øArrayListÈ´ÊÇÔÀ´µÄÒ»°ë
LinkedList(Á´±í)-ÊÇË«ÏòÁ´±í£¬Êʺϱä¸üºÜ¶àµÄList¡£
ÓÃÔÚFIFO£¬ÓÃaddList()¼ÓÈëÔªËØ removeFirst()ɾ³ýÔªËØ
ÓÃÔÚFILO,ÓÃaddFirst()/removeLast()
ListIteratorÌṩ˫Ïò±éÀúnext() previous()£¬¿Éɾ³ý¡¢Ìæ»»¡¢Ôö¼ÓÔªËØ
Èý¡¢Map
--ÓÃÓڹؼü×Ö/ÊýÖµ¶Ô£¬½Ï¸ßµÄ´æÈ¡ÐÔÄÜ¡£²»ÔÊÐíÖظ´µÄkey£¬µ«ÔÊÐíÖظ´µÄValue¡£
´¦ÀíMapµÄÈýÖÖ¼¯ºÏ
¹Ø¼ü×Ö¼¯KeySet() ÊýÖµ¼¯value() ÏîÄ¿¼¯enrySet()
Ëĸö¾ßÌå°æ±¾
HashMap-É¢ÁбíµÄͨÓÃÓ³Éä±í£¬ÎÞÐò£¬¿ÉÔÚ³õʼ»¯Ê±É趨Æä´óС£¬×Ô¶¯Ôö³¤¡£
LinkedHashMap-À©Õ¹HashMap£¬¶Ô·µ»Ø¼¯ºÏµü´úʱ£¬Î¬»¤²åÈë˳Ðò
WeakHashMap-»ùÓÚÈõÒýÓÃÉ¢ÁбíµÄÓ³Éä±í£¬Èç¹û²»±£³ÖÓ³Éä±íÍâµÄ¹Ø¼ü×ÖµÄÒýÓã¬ÔòÄÚ´æ»ØÊÕ³ÌÐò»á»ØÊÕËü
TreeMap-»ùÓÚƽºâÊ÷µÄÓ³Éä±í
ËÄ¡¢collectionsÀ࣬ÓÃÓÚͬ²½¼¯ºÏ£¬»¹Äܸı伯ºÏÖ»¶Á·½Ê½µÄÀà
e.g.:
Map mp=new HashMap();
mp=Collections.synchronizedMap(mp); //Éú³ÉḬ̈߳²È«µÄÓ³Éä±í
mp=Collections.unmodifiableMap(mp); //Éú³ÉÖ»¶ÁÓ³Éä±í
Îå¡¢HashtableÀà
ÊÇDictionary½á¹¹µÄ¾ßÌåʵÏÖ¡£
1¡¢Collection
Ïà¹ØÎĵµ£º
1.StudentList.java:
/**
*
* @author lucifer
*/
package JavaSerializable;
import java.util.*;
import java.io.*;
public class StudentList implements Serializable{
Vector list = new Vector(6);
public StudentList(){} ......
±ØÐëÓÃthis¹Ø¼ü×ÖµÄÈýÖÖÇé¿ö:
1.ÎÒÃÇÏëͨ¹ý¹¹Ôì·½·¨½«Íⲿ´«ÈëµÄ²ÎÊý¸³Öµ¸ø³ÉÔ±±äÁ¿,¶ø¹¹Ôì·½·¨µÄÐÎʽ²ÎÊýÓëÀà³ÉÔ±µÄ±äÁ¿ÃûÏàͬ,Õâʱ¾ÍÐèÒªthisÕâ¸ö¹Ø¼ü×ÖÀ´Çø±ð¾Ö²¿±äÁ¿ÓëÀà±äÁ¿;
2.¼ÙÉèÓÐÒ»¸öÈÝÆ÷ÀàºÍÒ»¸ö²¿¼þÀà,ÔÚÈÝÆ÷ÀàµÄij¸ö·½·¨ÖÐÒª´´½¨²¿¼þÀàµÄʵÀý¶ÔÏó,¶ø²¿¼þÀàµÄ¹¹Ôì·½·¨Òª½ÓÊÕÒ»¸ö´ú±íÆäËùÔÚÈÝÆ÷µÄ²ÎÊý,ÕâÊ±Ò²Ò ......
Ìõ¼þ£ºÒÑ°²×°J2SEºÍJ2EE¡£
Microsoft SQL Server 2000 Driver for JDBCÊÇ΢Èí¹«Ë¾Ãâ·ÑÌṩÃâ·ÑÏÂÔصÄÒ»¸öÈí¼þ£¬Çë·ÃÎÊ£º http://www.microsoft.com/sql/default.asp£¬ÏÂÔغóÎļþÃûΪ£ºsetup.exe£¬°²×°ºó£¬Ä¬ÈÏ·¾¶ÊÇ£º%Program Files%\Microsoft SQL Server 2000 Driver for JDBC£¬¸ÃĿ¼ÏÂLIBĿ¼ÀïÓÐ3¸öjarÎļþ¡£ ......
41¡¢ÊÇ·ñ¿ÉÒԼ̳ÐStringÀà?
StringÀàÊÇfinalÀà¹Ê²»¿ÉÒԼ̳С£
42¡¢swtichÊÇ·ñÄÜ×÷ÓÃÔÚbyteÉÏ£¬ÊÇ·ñÄÜ×÷ÓÃÔÚlongÉÏ£¬ÊÇ·ñÄÜ×÷ÓÃÔÚStringÉÏ?
switch£¨expr1£©ÖУ¬expr1ÊÇÒ»¸öÕûÊý±í´ïʽ¡£Òò´Ë´«µÝ¸ø switch ºÍ case Óï¾äµÄ²ÎÊýÓ¦¸ÃÊÇ int¡¢ short¡¢ char »òÕß byte¡£long,st ......
µ¥Ì¬¶¨Òå:
SingletonģʽÖ÷Òª×÷ÓÃÊDZ£Ö¤ÔÚJavaÓ¦ÓóÌÐòÖУ¬Ò»¸öÀàClassÖ»ÓÐÒ»¸öʵÀý´æÔÚ¡£
Singletonģʽ¾ÍΪÎÒÃÇÌṩÁËÕâÑùʵÏֵĿÉÄÜ¡£Ê¹ÓÃSingletonµÄºÃ´¦»¹ÔÚÓÚ¿ÉÒÔ½ÚÊ¡Äڴ棬ÒòΪËüÏÞÖÆÁËʵÀýµÄ¸öÊý£¬ÓÐÀûÓÚJavaÀ¬»ø»ØÊÕ£¨garbage col ......