下面是在给定数组中打印重复项的程序 .

public class PrintDuplicateArrays {

public static void main(String[] args) {

    int[] arr = { 1, 1, 2, 3, 4, 5, 6, 8, 8, 10, 10 };

    Set<Integer> hs = new HashSet<Integer>();

    for (int i = 0; i < arr.length; i++) {

        if (!hs.add(arr[i])) {
            System.out.print(arr[i]+ " ");
        }

    }

    //System.out.println(hs);

}

}

当我放置调试点,并按F6(eclipse IDE)时,它会打印所有值,当我删除调试点并只打印(只是运行程序)时,它只打印重复值 . 我很困惑为什么这种双重行为有和没有调试点 . 有人可以帮我理解这个问题吗?谢谢

  • 带调试点的输出

1 1 2 3 4 5 6 8 8 10 10

  • 没有调试点的输出

1 8 10