CollectionUtils { public static <T> Set<T> ofSet(T... values) { int size = values == null ? 0 : values.length; if (size < 1) { return emptySet(); } float loadFactor = 1f / ((size + 1) * 1.0f); if (loadFactor > 0.75f) { loadFactor = 0.75f; } Set<T> elements = new LinkedHashSet<>(size, loadFactor); for (int i = 0; i < size; i++) { elements.add(values[i]); } return unmodifiableSet(elements); } private  CollectionUtils(); @SuppressWarnings({"unchecked", "rawtypes"}) static List<T> sort(List<T> list); static List<String> sortSimpleName(List<String> list); static Map<String, Map<String, String>> splitAll(Map<String, List<String>> list, String separator); static Map<String, List<String>> joinAll(Map<String, Map<String, String>> map, String separator); static Map<String, String> split(List<String> list, String separator); static List<String> join(Map<String, String> map, String separator); static String join(List<String> list, String separator); static boolean mapEquals(Map<?, ?> map1, Map<?, ?> map2); static Map<String, String> toStringMap(String... pairs); @SuppressWarnings("unchecked") static Map<K, V> toMap(Object... pairs); static boolean isEmpty(Collection<?> collection); static boolean isNotEmpty(Collection<?> collection); static boolean isEmptyMap(Map map); static boolean isNotEmptyMap(Map map); static Set<T> ofSet(T... values); static int size(Collection<?> collection); static boolean equals(Collection<?> one, Collection<?> another); static int addAll(Collection<T> collection, T... values); static T first(Collection<T> values);  }
@Test public void testOfSet() { Set<String> set = ofSet(); assertEquals(emptySet(), set); set = ofSet(((String[]) null)); assertEquals(emptySet(), set); set = ofSet("A", "B", "C"); Set<String> expectedSet = new LinkedHashSet<>(); expectedSet.add("A"); expectedSet.add("B"); expectedSet.add("C"); assertEquals(expectedSet, set); }