When I came across the following example I did not expect the results that the program has printed
hehe…
Question: What does this program print? Why?
[java]
import java.util.*;
public class SetList {
public static void main(String[] args) {
Set<Integer> set =
new TreeSet<Integer>();
List<Integer> list =
new ArrayList<Integer>();
for (int i = -3; i < 3; i++) {
set.add(i);
list.add(i);
}
for (int i = 0; i < 3; i++) {
set.remove(i);
list.remove(i);
}
System.out.println(set + " " + list);
}
}
[/java]
Looking forward for your answers dear readers
Resources:
Effective Java