1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
      java項(xiàng)目中什么情況下HashCode會(huì)出現(xiàn)重復(fù)-創(chuàng)新互聯(lián)

      java項(xiàng)目中什么情況下HashCode會(huì)出現(xiàn)重復(fù)?針對(duì)這個(gè)問題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡(jiǎn)單易行的方法。

      創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),邊壩企業(yè)網(wǎng)站建設(shè),邊壩品牌網(wǎng)站建設(shè),網(wǎng)站定制,邊壩網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,邊壩網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。

      java的缺省算法:  

      public int hashCode() { 
        int h = hash; 
        if (h == 0) { 
          int off = offset; 
          char val[] = value; 
          int len = count; 
       
            for (int i = 0; i < len; i++) { 
              h = 31*h + val[off++]; 
            } 
            hash = h; 
          } 
          return h; 
        }

      但是什么情況下會(huì)重復(fù)?下面是測(cè)試代碼

      import java.util.HashMap; 
       
      public class Test { 
       
        static HashMap map = new HashMap(); 
       
        private static char startChar = 'A'; 
       
        private static char endChar = 'z'; 
       
        private static int offset = endChar - startChar + 1; 
       
        private static int dup = 0; 
       
        public static void main(String[] args) { 
          int len = 3; 
          char[] chars = new char[len]; 
          tryBit(chars, len); 
          System.out.println((int)Math.pow(offset, len) + ":" + dup); 
        } 
       
        private static void tryBit(char[] chars, int i) { 
          for (char j = startChar; j <= endChar; j++) { 
            chars[i - 1] = j; 
            if (i > 1) 
              tryBit(chars, i - 1); 
            else 
              test(chars); 
          } 
        } 
       
        private static void test(char[] chars) { 
       
          String str = new String(chars).replaceAll("[^a-zA-Z_]", "").toUpperCase();// 195112:0 
          //String str = new String(chars).toLowerCase();//195112:6612 
          //String str = new String(chars).replaceAll("[^a-zA-Z_]","");//195112:122500 
          //String str = new String(chars);//195112:138510 
          int hash = str.hashCode(); 
          if (map.containsKey(hash)) { 
            String s = (String) map.get(hash); 
            if (!s.equals(str)) { 
              dup++; 
              System.out.println(s + ":" + str); 
            } 
          } else { 
            map.put(hash, str); 
            // System.out.println(str); 
          } 
        } 
      }

      在A-z范圍內(nèi)有特殊字符,從結(jié)果看,僅僅3位長(zhǎng)度的字符串:

      不處理: 138510次重復(fù)

      去掉字母意外字符: 122500次重復(fù)

      所有字符轉(zhuǎn)小寫:6612次重復(fù)(少了很多)

      去掉字母意外字符,并且轉(zhuǎn)小寫:沒有重復(fù)!4位字符串也沒見重復(fù)

      不難看出:

      1. 缺省實(shí)現(xiàn)為英文字母優(yōu)化
      2. 字母大小寫可能導(dǎo)致重復(fù)

      可能:

      長(zhǎng)字符串可能hashcode重復(fù)
      中文字符串和特殊字符可能hashcode重復(fù)

      關(guān)于java項(xiàng)目中什么情況下HashCode會(huì)出現(xiàn)重復(fù)問題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。


      標(biāo)題名稱:java項(xiàng)目中什么情況下HashCode會(huì)出現(xiàn)重復(fù)-創(chuàng)新互聯(lián)
      標(biāo)題鏈接:http://www.ef60e0e.cn/article/cegcop.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        大荔县| 项城市| 平安县| 邳州市| 太白县| 嘉善县| 安阳县| 依兰县| 禄劝| 辉县市| 邹城市| 韶山市| 山东省| 阳泉市| 烟台市| 卓尼县| 滕州市| 墨竹工卡县| 施甸县| 多伦县| 巴林左旗| 堆龙德庆县| 孟津县| 定西市| 洱源县| 衡东县| 星子县| 博客| 蒙阴县| 南阳市| 松原市| 建始县| 临桂县| 电白县| 镇江市| 元朗区| 彭州市| 荣昌县| 宜阳县| 昔阳县| 孝义市|