list<string>如何去除重复数据

2025-02-26 12:51:51
推荐回答(1个)
回答1:

属性是???? 先给你一个看看是不是你需要的好了, // 利用 Set 的特性,将所有项目放入 Set //中即可移除重复的项目 Set stringSet = new HashSet(); for (String element : duplicateArray) { stringSet.add(element); } // Set.size() 为不重复项目的个数 String nonDuplicateArray[] = new String[stringSet.size()]; // 将 Set 中的项目取出放到 nonDuplicateArray 中 Object[] tempArray = stringSet.toArray(); for (int i = 0; i < tempArray.length; i++) { nonDuplicateArray[i] = (String) tempArray[i]; }