Convert Collection to Set
@param collection Collection
@return Set
550711
public static <T> Set<T> getSet(Collection<T> collection) {
    Set<T> set = new LinkedHashSet<T>();
    set.addAll(collection);

    return set;
  }
372310
public static final <T> Set<Set<T>> powerSet(Set<T> set)
    {
        Set<Set<T>> powerSet = new HashSet<>();
        powerSet.add(Collections.EMPTY_SET);
        powerSet(powerSet, set);
        return powerSet;
    }
1184170
public function setMany(array $collection)
    {
        foreach ($collection as $key => $value) {
            $this->set($key, $value);
        }

        return $this;
    }
1150530
public static <T> Set<T> unmodifiableSet(Set<? extends T> s) {
		return Collections.unmodifiableSet(s);
	}
384252
public static <T> HashSet<T> newHashSet(Collection<T> collection) {
		return newHashSet(false, collection);
	}
946987
public static ArrayList<String> toList( Set<String> set )
	{
		int n = set.size();
		ArrayList<String> list = new ArrayList<String>( n );
		for (String string : set)
		{
			list.add(string);
		}
		return list;
	}
747844
function setToArray(set) {
  var array = new Array();
  set.forEach(function(value) {
    array.push(value);
  }, null);
  return array;
}
1016366
private static <E> Collection<E> toCollection(Iterable<E> iterable) {
		return (iterable instanceof Collection) ? (Collection<E>)iterable : Lists.newArrayList(iterable.iterator());
	}
1180476
public static <T> Set<T> union(Collection<Set<T>> sets) {
		Set<T> result = new HashSet<>();
		if (sets.isEmpty()) {
			return result;
		}
		Iterator<Set<T>> iter = sets.iterator();
		result.addAll(iter.next());

		if (sets.size() == 1) {
			return result;
		}

		while (iter.hasNext()) {
			result.addAll(iter.next());
		}
		return result;
	}
558064
public static <T> Set<T> intersection(Collection<T> parentCollection, Collection<T> removeFromCollection) {
        Set<T> results = new HashSet<>(parentCollection);
        results.retainAll(removeFromCollection);
        return results;
    }
104066
public static <T> Set<T> toSet(Iterable<T> iterable)
   {
      if (iterable == null)
      {
         return null;
      }
      else if (iterable instanceof Set)
      {
         return (Set<T>) iterable;
      }
      else
      {
         Set<T> list = new LinkedHashSet<>();
         for (T obj : iterable)
         {
            list.add(obj);
         }
         return list;
      }
   }
1061537
public static Set<Object> toCollection(final Object obj) {
        val c = new LinkedHashSet<Object>();
        if (obj == null) {
            LOGGER.trace("Converting null obj to empty collection");
        } else if (obj instanceof Collection) {
            c.addAll((Collection<Object>) obj);
            LOGGER.trace("Converting multi-valued element [{}]", obj);
        } else if (obj instanceof Map) {
            val map = (Map) obj;
            val set = (Set<Map.Entry>) map.entrySet();
            c.addAll(set.stream().map(e -> Pair.of(e.getKey(), e.getValue())).collect(Collectors.toSet()));
        } else if (obj.getClass().isArray()) {
            if (byte[].class.isInstance(obj)) {
                c.add(obj);
            } else {
                c.addAll(Arrays.stream((Object[]) obj).collect(Collectors.toSet()));
            }
            LOGGER.trace("Converting array element [{}]", obj);
        } else if (obj instanceof Iterator) {
            val it = (Iterator) obj;
            while (it.hasNext()) {
                c.add(it.next());
            }
        } else if (obj instanceof Enumeration) {
            val it = (Enumeration) obj;
            while (it.hasMoreElements()) {
                c.add(it.nextElement());
            }
        } else {
            c.add(obj);
            LOGGER.trace("Converting element [{}]", obj);
        }
        return c;
    }
276986
public static <T> Optional<Iterable<T>> convertCollection(Class<? extends Iterable<T>> iterableType, Collection<T> collection) {
        if (iterableType.isInstance(collection)) {
            return Optional.of(collection);
        }
        if (iterableType.equals(Set.class)) {
            return Optional.of(new HashSet<>(collection));
        }
        if (iterableType.equals(Queue.class)) {
            return Optional.of(new LinkedList<>(collection));
        }
        if (iterableType.equals(List.class)) {
            return Optional.of(new ArrayList<>(collection));
        }
        if (!iterableType.isInterface()) {
            try {
                Constructor<? extends Iterable<T>> constructor = iterableType.getConstructor(Collection.class);
                return Optional.of(constructor.newInstance(collection));
            } catch (Throwable e) {
                return Optional.empty();
            }
        }
        return Optional.empty();
    }
396985
public function setCollection($collection)
    {
        $this->collection = (array) $collection;
        $this->setCount(count($this->collection));

        return $this;
    }
1200784
public static function toList($collection) {
		$list = new ArrayList();
		foreach ($collection as $v) {
			$list->add(self::toCollection($v));
		}
		return $list;
	}
17047
public function setCollection($collection)
    {
        $this->collection = $collection;

        $this->collection->setCurPage($this->getCurrentPage());

        // we need to set pagination only if passed value integer and more that 0
        $limit = (int)$this->getLimit();
        if ($limit) {
            $this->collection->setPageSize($limit);
        }
        if ($this->getCurrentOrder()) {
            $this->collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
        }

        return $this;
    }
90139
public static <T> T[] toArray(final Collection<T> collection) {

        T next = getFirstNotNullValue(collection);
        if (next != null) {
            Object[] objects = collection.toArray();
            @SuppressWarnings("unchecked")
            T[] convertedObjects = (T[]) Array.newInstance(next.getClass(), objects.length);
            System.arraycopy(objects, 0, convertedObjects, 0, objects.length);
            return convertedObjects;
        } else {
            return null;
        }
    }