<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 72, comments - 66, trackbacks - 0, articles - 0

    2009年12月23日


    sudo vim /etc/vmware/config

    在最下面添加一句話:
    xkeymap.nokeycodeMap = true

    posted @ 2010-06-09 15:39 Fingki.li 閱讀(590) | 評論 (0)編輯 收藏

    在使用Iterator處理Collection時,注意java.util.ConcurrentModificationException。
    1.如果你僅僅是對collection進行遍歷查詢,那么不必擔心什么。
    2.但如果你在遍歷過程中要對collection進行刪除,那么你就要注意了。
    For example:
    private void testDel() {  
    1.     List<String> list = new ArrayList<String>();  
    2.     for (int i = 0; i < 10; i++) {  
    3.         String str = "td" + i;  
    4.         list.add(str);  
    5.     }  
    6.   
    7.     for (Iterator it = list.iterator(); it.hasNext();) {  
    8.         String str = (String) it.next();  
    9.         if (str.equals("td5")) {  
    10.             // list.remove(str);  // 刪除方法一 
    11.             it.remove();  // 刪除方法二 
    12.         }  
    13.     }  

    上面的代碼運行沒有問題,但如果你用“方法一”替代“方法二”,則會出現java.util.ConcurrentModificationException。
    (用for-each遍歷也會出個類似問題)
    具體原因是可以看一下先看看List中的remove方法源碼:
    1. public boolean remove(Object o) {  
    2.     if (o == null) {  
    3.         for (int index = 0; index < size; index++)  
    4.             if (elementData[index] == null) {  
    5.                 fastRemove(index);  
    6.                 return true;  
    7.             }  
    8.     } else {  
    9.         for (int index = 0; index < size; index++)  
    10.             if (o.equals(elementData[index])) {  
    11.                 fastRemove(index);  
    12.                 return true;  
    13.             }  
    14.     }  
    15.     return false;  
    16. }  
    17.   
    18. private void fastRemove(int index) {  
    19.     modCount++; // 特別注意這里,這里只增加了modCount的值  
    20.     int numMoved = size - index - 1;  
    21.     if (numMoved > 0)  
    22.         System.arraycopy(elementData, index + 1, elementData, index,  
    23.                 numMoved);  
    24.     elementData[--size] = null; // Let gc do its work  

    接著看。刪除后得到下一個元素的代碼,it.next():  it為AbstractList的內部類Iterator的一個實例。
    1. public E next() {  
    2.     checkForComodification();  
    3.     try {  
    4.         E next = get(cursor);  
    5.         lastRet = cursor++;  
    6.         return next;  
    7.     } catch (IndexOutOfBoundsException e) {  
    8.         checkForComodification();  
    9.         throw new NoSuchElementException();  
    10.     }  
    11. }  
    12.   
    13. final void checkForComodification() {  //注意這個方法
    14.     if (modCount != expectedModCount)  //檢查這兩個值是否相同
    15.         throw new ConcurrentModificationException();  

    最后看Iterator的remove()方法的源代碼:
    1. public void remove() {  
    2.     if (lastRet == -1)  
    3.         throw new IllegalStateException();  
    4.     checkForComodification();  
    5.     try {  
    6.         AbstractList.this.remove(lastRet);  
    7.         if (lastRet < cursor)  
    8.             cursor--;  
    9.         lastRet = -1;  
    10.         expectedModCount = modCount; // 設置expectedModCount  
    11.     } catch (IndexOutOfBoundsException e) {  
    12.         throw new ConcurrentModificationException();  
    13.     }  
    14. }  
    15.   
    16. final void checkForComodification() {  
    17.     if (modCount != expectedModCount)  
    18.         throw new ConcurrentModificationException();  

    這下就明白了,list的remove方法只修改了modCount值,而iterator的remove能同步modCount和expectedModCount.



    posted @ 2010-03-02 12:22 Fingki.li 閱讀(5084) | 評論 (1)編輯 收藏

    Ubuntu 時區時間設置:
    執行
    tzselect(有的版本用tzconfig)
    按照提示進行選擇時區
    sudo cp /usr/share/zoneinfo/Asia/ShangHai /etc/localtime
    執行
    sudo ntpdate cn.pool.ntp.org
    cn.pool.ntp.org是位于中國的公共NTP服務器,用來同步你的時間

    時間
    sudo date

    posted @ 2010-03-02 11:51 Fingki.li 閱讀(466) | 評論 (0)編輯 收藏

    各國語言代碼列表:
    English 1033 1033
    German 1031 1031
    French 1036 1036
    Japanese 1041 1041
    Danish 1030 1030
    Spanish 3082 3082
    Italian 1040 1040
    Dutch 1043 1043
    Norwegian 2068 2068
    Portuguese 2070 2070
    Finnish 1035 1035
    Swedish 1053 1053
    Czech 1029 1029
    Hungarian 1038 1038
    Polish 1045 1045
    Romanian 1048 1048
    Croatian 1050 1050
    Slovak 1051 1051
    Slovene 1060 1060
    Greek 1032 1032
    Bulgarian 1026 1026
    Russian 1049 1049
    Turkish 1055 1055
    British English 2057 1033
    Estonian 1061 1061
    Latvian 1062 1062
    Lithuanian 1063 1063
    Brazilian 1046 1046
    Traditional Chinese 1028 1028
    Korean 1042 1042
    Simplified Chinese 2052 2052
    Arabic 1025 1025
    Thai 1054 1054

    posted @ 2009-12-23 17:33 Fingki.li 閱讀(985) | 評論 (0)編輯 收藏

    主站蜘蛛池模板: 国产激情免费视频在线观看| 亚洲另类小说图片| 美女黄频免费网站| 日韩精品视频免费观看| 在线a亚洲老鸭窝天堂av高清| 国产曰批免费视频播放免费s| 亚洲伊人久久大香线蕉在观| 久久不见久久见中文字幕免费 | 久久综合久久综合亚洲| 97碰公开在线观看免费视频| 亚洲男人的天堂久久精品 | 免费大黄网站在线观| 黄色免费网址大全| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 久久夜色精品国产亚洲AV动态图 | 国产AV无码专区亚洲AV琪琪| 亚洲 小说区 图片区 都市| 成人福利在线观看免费视频| 一本色道久久综合亚洲精品高清 | 2019中文字幕在线电影免费 | 在线看片无码永久免费视频| 亚洲一区二区三区丝袜| 国产免费av片在线播放| 一级中文字幕乱码免费| 亚洲精品高清视频| 无人在线观看免费高清视频| 噜噜噜亚洲色成人网站| 亚洲国产精品无码AAA片| 黄页网站在线观看免费高清| 特级无码毛片免费视频| 亚洲V无码一区二区三区四区观看| 99re免费视频| 美女的胸又黄又www网站免费| 亚洲综合网站色欲色欲| 美女被cao免费看在线看网站| 看全免费的一级毛片| 久久精品夜色国产亚洲av| 成人免费看黄20分钟| 男女一进一出抽搐免费视频 | 免费在线中文日本| 亚洲精品国产av成拍色拍|