I came across an interview question.
what is the result of the code below.
package com.demo; import java.util.HashSet; import java.util.Set; public class Test { public static void main(String[] args) { Set<Short> set=new HashSet<Short>(); for (short i = 0; i < 10; i++){ set.add(i); set.remove(i-1); } System.out.println(set.size()); } }
It displays the result: 10
But I'm confused why its output is 10.
Anyone can answer me, please, what is happening here.
thanks
SItansu
source share