net.dongliu.commons.lang.collection.Sets Maven / Gradle / Ivy
package net.dongliu.commons.lang.collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
* utils method for set
*
* @author Dong Liu
*/
public class Sets {
/**
* get a set.
*
* {@code Set list = Sets.of("test", "test2");}
*
*/
@SafeVarargs
public static Set of(T... values) {
Set set = new HashSet<>();
Collections.addAll(set, values);
return set;
}
/**
* get immutable set
*/
@SafeVarargs
public static Set immutable(T... values) {
return Collections.unmodifiableSet(of(values));
}
/**
* get immutable list
*/
public static Set immutable(Set set) {
return Collections.unmodifiableSet(set);
}
}