Set<String> set = new HashSet<String>(); set.add("11"); set.add("2"); set.add("1"); //output result: [11, 1, 2] //The order of elements has nothing to do with the order of placement, and is related to the HashCode of the element. System.out.println(set); Set<String> set2 = new LinkedHashSet<String>(); set2.add("11"); set2.add("2"); set2.add("1"); //output result: [11, 2, 1] // Consistent with the order in which they were placed. System.out.println(set2); Set<String> set3 = new LinkedHashSet<String>(); set3.add("a"); set3.add("a"); //Output result: [a] //Whether it is HashSet or LinkedHashSet, no duplicate values will be put into it. System.out.println(set3);