Java Utililty Methods List to Set

List of utility methods to do List to Set

Description

The list of methods to do List to Set are organized into topic(s).

Method

SetlistToSet(final BsonArray array)
list To Set
if (array == null || array.isEmpty()) {
    return Collections.emptySet();
} else {
    Set<String> set = new HashSet<String>();
    for (BsonValue value : array) {
        set.add(value.asString().getValue());
    return set;
...
SetlistToSet(List list)
list To Set
Set set = new HashSet();
if (list != null) {
    for (Iterator iter = list.iterator(); iter.hasNext();) {
        Object object = (Object) iter.next();
        if (object != null) {
            set.add(object);
return set;
SettoSet(List sources)
to Set
Set<Object> targets = Collections.emptySet();
targets.addAll(sources);
return targets;
SettoSet(List list, Comparator comparator)
Returns the List as an Set either ordered or as-is, if the comparator is null.
Set<String> set;
if (comparator == null)
    set = new LinkedHashSet<>();
else
    set = new TreeSet<>(comparator);
set.addAll(list);
return set;
SettoSet(List list)
to Set
return Collections.unmodifiableSet(new HashSet<>(list));
SettoSet(List list)
to Set
Set<T> set = new HashSet<T>();
for (T t : list) {
    if (!set.contains(t)) {
        set.add(t);
return set;
SettoSet(Optional> list)
Returns a new Set populated by all elements in the given list of strings Returns an empty set if the given Optional is empty, or if the list contained in the Optional is empty
List<String> elements = list.orElse(Collections.emptyList());
return new HashSet<>(elements);