file:///C:/Users/臭小子/AppData/Roaming/Tencent/Users/943177923/QQ/WinTemp/RichOle/KW@F$BDNCE1H5_S2EOZ8U%600.pngimport java.util.HashSet;
class Demo1 {
public static void main(String[] args) {
int[] arr = {4,3,1,2,4,2,3};
//char[] arr = {'c','b','b','c','a','h','e'};
HashSet<Integer> hs = new HashSet<>();
for (int i = 0;i < arr.length ;i++ ) {
hs.add(arr);
}
for(int h:hs){
System.out.print(h);
}
}
}
传int 遍历的结果是有序的 char遍历的结果是无序的 是不是因为Integer重写了equals或者Compare方法吗 现在set集合这章听的脑子一团浆糊
file:///C:/Users/臭小子/AppData/Roaming/Tencent/Users/943177923/QQ/WinTemp/RichOle/KW@F$BDNCE1H5_S2EOZ8U%600.png
|
|