java 去除数组重复数据,并输出重复数据值

/**
 * 去除重复数据
 * @author Sunqinbo
 */
public class RemoveDuplicateData {
	public static void main(String[] args) {
		Integer[] a = new Integer[] { 1, 4, 5, 2, -6, 5, 9, 10, 10 };

		Set<Integer> set = new HashSet<Integer>();
		for (int i = 0; i < a.length; i++) {
			boolean b = set.add(a[i]);
			if (!b) {
				System.out.println("重复数据:" + a[i] + "   索引位置:" + i);
			}
		}
	}
}


posted on 2013-10-17 10:30  love so much  阅读(804)  评论(0编辑  收藏  举报

导航