´«ÖDz¥¿Í2009 12 24 Èý¡¢java»ù´¡¼ÓÇ¿(3)
Ò»¡¢·ºÐÍ(Generic)
JDK5ÒÔÇ°£¬¶ÔÏó±£´æµ½¼¯ºÏÖоͻáʧȥÆäÌØÐÔ£¬È¡³öʱͨ³£Òª³ÌÐòÔ±ÊÖ¹¤½øÐÐÀàÐ͵ÄÇ¿ÖÆת»»£¬ÕâÑù²»¿É±ÜÃâ¾Í»áÒý·¢³ÌÐòµÄһЩ°²È«ÐÔÎÊÌâ
Ø·ºÐεÄ×÷Óãº
JDK5ÖеķºÐÎÔÊÐí³ÌÐòÔ±ÔÚ±àд¼¯ºÏ´úÂëʱ£¬¾ÍÏÞÖƼ¯ºÏµÄ´¦ÀíÀàÐÍ£¬´Ó¶ø°ÑÔÀ´³ÌÐòÔËÐÐʱ¿ÉÄÜ·¢ÉúÎÊÌ⣬ת±äΪ±àÒëʱµÄÎÊÌ⣬ÒÔ´ËÌá¸ß³ÌÐòµÄ¿É¶ÁÐÔºÍÎȶ¨ÐÔ(ÓÈÆäÔÚ´óÐͳÌÐòÖиüΪͻ³ö)¡£
×¢Ò⣺·ºÐÍÊÇÌṩ¸øjavac±àÒëÆ÷ʹÓõģ¬ËüÓÃÓÚÏÞ¶¨¼¯ºÏµÄÊäÈëÀàÐÍ£¬ÈñàÒëÆ÷ÔÚÔ´´úÂ뼶±ðÉÏ£¬¼´µ²×¡Ïò¼¯ºÏÖвåÈë·Ç·¨Êý¾Ý¡£µ«±àÒëÆ÷±àÒëÍê´øÓзºÐεÄjava³ÌÐòºó£¬Éú³ÉµÄclassÎļþÖн«²»ÔÙ´øÓзºÐÎÐÅÏ¢£¬ÒÔ´Ëʹ³ÌÐòÔËÐÐЧÂʲ»Êܵ½Ó°Ï죬Õâ¸ö¹ý³Ì³Æ֮Ϊ“²Á³ý”¡£
Ø·ºÐ͵äÐÍÓ¦Óãº
1¡¢ ʹÓõü´úÆ÷µü´ú·ºÐμ¯ºÏÖеÄÔªËØ¡£
Eg. List<String> list = new ArrayList<String>();
list.add("Acegi");
list.add("Red5");
list.add("OpenMeettings");
Iterator<String> it = list.iterator();
while(it.hasNext()){
String bookname = it.next();
… …
}
2¡¢Ê¹ÓÃÔöÇ¿forÑ»·µü´ú·ºÐμ¯ºÏÖеÄÔªËØ¡£
Eg. for(String bookname : list){
… …
}
3¡¢´æÈ¡HashMapÖеÄÔªËØ¡£
Eg. Map<Integer,String> map = new HashMap<Integer,String>();
map.put(1, " Acegi ");
map.put(2, " Red5");
map.put(3, " OpenMeettings ");
S
Ïà¹ØÎĵµ£º
public class Factory {
private static Factory factory;
private static Object classLock=Factory.class;
private Factory(){}
public static Factory getFactory(){
synchronized(classLock){
......
Ḭ̈߳²È«µÄ¼¯ºÏ°üº¬2¸öÎÊÌâ
1.¶àÏ̲߳¢·¢ÐÞ¸ÄÒ» ¸ö ¼¯ºÏ Ôõô°ì£¿
2.Èç¹ûµü´úµÄ¹ý³ÌÖÐ ¼¯ºÏ ±»ÐÞ¸ÄÁËÔõô°ì£¿
a.Ò»¸öÏß³ÌÔÚµü´ú£¬ÁíÒ»¸öÏß³ÌÔÚÐÞ¸Ä
b.ÔÚͬһ¸öÏß³ÌÄÚÓÃͬһ¸öµü´úÆ÷¶ ......
java.lang.string.split
split ·½·¨
½«Ò»¸ö×Ö·û´®·Ö¸îΪ×Ó×Ö·û´®£¬È»ºó½«½á¹û×÷Ϊ×Ö·û´®Êý×é·µ»Ø¡£
stringObj.split([separator£¬[limit]])
stringObj
±ØÑ¡Ïî¡£Òª±»·Ö½âµÄ String ¶ÔÏó»òÎÄ×Ö¡£¸Ã¶ÔÏ󲻻ᱻ split ·½·¨Ð޸ġ£
separator
¿ÉÑ¡Ïî¡£×Ö·û´®»ò ÕýÔò±í´ïʽ ¶ÔÏó£¬Ëü±êʶÁË·Ö¸ô×Ö·û´®Ê±Ê¹ÓõÄÊÇÒ»¸ö»¹ÊǶà ......
±¾ÈËÕýÔÚѧϰJava£¬ÄÇЩ֪ʶµã¶¼Ñ§µÃºÜºÃ£¬µ«Ò»µ©ÒªÎÒÓÃËùѧµÄ֪ʶ×ö¸öÏîÄ¿³öÀ´ÎÒ¾ÍÎÞ´ÓÏÂÊÖ£¬²»ÖªµÀ´ÓÄÄÀï×öÆð²ÅºÃ£¡Ò»·½ÃæµÄÔÒòÊÇÎÒµÄÔĶÁÁ¿Ì«ÉÙÁË£¬¶þÕß¾Ñé²»×㣡ÎÒÕý½¹¼±×ÅÔõô¸Ä±äÎÒÕâÖÖ״̬£¬ËùÒÔÏëÕÒЩ×öÏîÄ¿µÄ½Ì²ÄÀ´×Ôѧ£¬µ«Õæ²»ÖªµÀ¸Ã¿´ÄÄЩ½Ì²ÄºÃ£¬ËùÒÔÔÚ´ËÏò¸÷λÏîÄ¿¸ßÊÖÇë½Ì£¬Çë¸øÎÒһЩ½¨Òé»òÍƼö¸øÎÒһЩ½Ì ......
ΪÁË·½±ã£¬ÓÐʱÎÒÃÇÐèÒªÖ±½Ó½«±¾µØÎļþ»ò×Ö·û»òͼƬֱ½ÓÍÏקµ½Í¼ÐÎÉÏ£¬ÈÃ×é¼þ×Ô¶¯´ò¿ªÍÏקµÄÎļþ¡£»ùÓÚÕâÖÖ˼Ï룬ÎÒдÁËÈçÏ´úÂëʵÏÖÕâ¸öÍÏק¼àÌýµÄ¹¦ÄÜ¡£
1.UIÔ´Âë
package ibees.desktop;
import javax.swing.BorderFactory;
import javax.swing ......