重慶分公司,新征程啟航
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)
今天就跟大家聊聊有關(guān)List和hashSet中怎么去掉重復(fù)值,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
int a[] = { 2, 3, 5, 4, 1, 2, 3, 4, 6 };
List
for (int i = 0; i < a.length; i++) {
if (!list.contains(a[i])) {
list.add(a[i]);
}
}
System.out.println("去除重復(fù)后的list集合" + list);
}
}
Integer[] nums = { 5, 5, 6, 6, 6, 8, 8, 7, 11, 12, 12 };
// HashSet hset = new HashSet(Arrays.asList(nums));
TreeSet
Iterator i = hset.iterator();
while(i.hasNext()){
System.out.println(i.next());
}
看完上述內(nèi)容,你們對(duì)List和hashSet中怎么去掉重復(fù)值有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道,感謝大家的支持。