如何在hashset中快速找到重复的元素呢?方法很多,下面是其中一个办法:
利用了hashset晒选重复的特性,如果针对set中再增加重复的元素,就会报false了
int[] array = {1,1,2,3,4,5,6,7,8,8};
Set<Integer> set = new HashSet<Integer>();
for(int i = 0; i < array.length ; i++)
{
if(set.add(array[i]) == false)
{
System.out.println("Duplicate element found : " + array[i]);
}
}
利用了hashset晒选重复的特性,如果针对set中再增加重复的元素,就会报false了