为何Hashset、TreeSet、LinkedHashSet内部元素的排序结果不一样?
package demo;
import java.util.LinkedHashSet;
import java.util.Set;
import org.junit.Test;
public class union_List {
@Test
public void test1() {
Set<Integer> s = new LinkedHashSet<>();// HashSet,TreeSet
int[] a = { 10, 11, 12, 13, 14, 15, 16 };
for_each(a, s);
int[] b = { 20, 12, 16, 17, 18, 19 };
for_each(b, s);
System.out.println(s);
}
// 把数组中所有的元素添加到set集合中
public void for_each(int[] a, Set<Integer> s) {
for (int i : a)
s.add(i);
}
}