Java tutorial
//package com.java2s; import java.util.*; public class Main { public static <E> Set<E> toSet(Iterable<E> iterable) { if (iterable instanceof Set) { return (Set<E>) iterable; } Set<E> set = new HashSet<>(); if (iterable != null) { for (E e : iterable) { set.add(e); } } return set; } }