HashSet.contains
生活随笔
收集整理的這篇文章主要介紹了
HashSet.contains
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
HashSet<String> hst1 = new HashSet<String>();
hst1.add("1");
String ss = "123";
System.out.println(ss.charAt(0));
if (hst1.contains(ss.charAt(0)))
System.out.println("yes");
else
hst1.add("1");
String ss = "123";
System.out.println(ss.charAt(0));
if (hst1.contains(ss.charAt(0)))
System.out.println("yes");
else
System.out.println("no");
輸出是no
這是因為contains內部是比較hash值的,字符串“1”的hash值和字符'1'的哈希值不一樣
總結
以上是生活随笔為你收集整理的HashSet.contains的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NoSQL架构实践
- 下一篇: 通用的Java hashCode重写方案