日期:2014-05-20 浏览次数:20662 次
public static void main(String[] args) { String[] strs = new String[]{"a","a","b","b","c","c","d","d","e","e"}; System.out.println("起始含有重复数据的数组:"); for(String s : strs){ System.out.println(s); } Set<String> set = new HashSet<String>(); for(String str : strs){ set.add(str); } strs = new String[set.size()]; Iterator<String> iterator = set.iterator(); int i = 0; while(iterator.hasNext()){ strs[i++] = iterator.next(); } System.out.println("去掉重复数据的数组:"); for(String s : strs){ System.out.println(s); } }