java的字母ASCII 值與 hashcode的關係??

 

 

概念

  ASCII :

    ASCII ((American Standard Code for Information Interchange): 美國信息交換標準代碼)是基於拉丁字母的一套電腦編碼系統,主要用於顯示現代英語和其他西歐語言。它是最通用的信息交換標準,並等同於國際標準ISO/IEC 646。ASCII第一次以規範標準的類型發表是在1967年,最後一次更新則是在1986年,到目前爲止共定義了128個字符

hashcode

   java中,就是把任意長度的輸入,通過散列算法,變換成固定長度的輸出,該輸出就是散列值也可稱爲 hashcode值

 

那ASCII 值與 hashcode到底什麼關係呢?

猜是沒用的

直接上代碼

public class ASCIIValue {
    public static void main(String[] args) {
        char[] arr = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
                'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
                'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F',
                'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
                'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
        System.out.println("運行結果如下:");
        System.out.println("--------------------------------");
        for(int i=0; i<arr.length; i++){
            System.out.println(arr[i] + ":" + (int)arr[i]+",hashcode:" + String.valueOf(arr[i]).hashCode());
        }
    }
}

運行結果

 

運行結果如下:
--------------------------------
a:97,hashcode:97
b:98,hashcode:98
c:99,hashcode:99
d:100,hashcode:100
e:101,hashcode:101
f:102,hashcode:102
g:103,hashcode:103
h:104,hashcode:104
i:105,hashcode:105
j:106,hashcode:106
k:107,hashcode:107
l:108,hashcode:108
m:109,hashcode:109
n:110,hashcode:110
o:111,hashcode:111
p:112,hashcode:112
q:113,hashcode:113
r:114,hashcode:114
s:115,hashcode:115
t:116,hashcode:116
u:117,hashcode:117
v:118,hashcode:118
w:119,hashcode:119
x:120,hashcode:120
y:121,hashcode:121
z:122,hashcode:122
A:65,hashcode:65
B:66,hashcode:66
C:67,hashcode:67
D:68,hashcode:68
E:69,hashcode:69
F:70,hashcode:70
G:71,hashcode:71
H:72,hashcode:72
I:73,hashcode:73
J:74,hashcode:74
K:75,hashcode:75
L:76,hashcode:76
M:77,hashcode:77
N:78,hashcode:78
O:79,hashcode:79
P:80,hashcode:80
Q:81,hashcode:81
R:82,hashcode:82
S:83,hashcode:83
T:84,hashcode:84
U:85,hashcode:85
V:86,hashcode:86
W:87,hashcode:87
X:88,hashcode:88
Y:89,hashcode:89
Z:90,hashcode:90

根據結果判斷,他們是相等的

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章