@Test public void iterableToSet() { Iterable<Integer> numbers = Arrays.asList(1, 2, 3, 3, 4, 5); Set<Integer> set = Iterables.toSet(numbers); assertThat(set).hasSize(5).containsAll(numbers); }
@Nonnull public static <T> Set<T> toSet(@Nonnull Iterable<T> source) { if (source instanceof Set) { return (Set<T>) source; } else { Set<T> set = new HashSet<>(); for (T item : source) { set.add(item); } return set; } }
Iterables { @Nonnull public static <T> Set<T> toSet(@Nonnull Iterable<T> source) { if (source instanceof Set) { return (Set<T>) source; } else { Set<T> set = new HashSet<>(); for (T item : source) { set.add(item); } return set; } } }
Iterables { @Nonnull public static <T> Set<T> toSet(@Nonnull Iterable<T> source) { if (source instanceof Set) { return (Set<T>) source; } else { Set<T> set = new HashSet<>(); for (T item : source) { set.add(item); } return set; } }  }
Iterables { @Nonnull public static <T> Set<T> toSet(@Nonnull Iterable<T> source) { if (source instanceof Set) { return (Set<T>) source; } else { Set<T> set = new HashSet<>(); for (T item : source) { set.add(item); } return set; } }  @Nonnull static List<T> toList(@Nonnull final Iterable<T> iterable); @Nonnull static Set<T> toSet(@Nonnull Iterable<T> source); }
Iterables { @Nonnull public static <T> Set<T> toSet(@Nonnull Iterable<T> source) { if (source instanceof Set) { return (Set<T>) source; } else { Set<T> set = new HashSet<>(); for (T item : source) { set.add(item); } return set; } }  @Nonnull static List<T> toList(@Nonnull final Iterable<T> iterable); @Nonnull static Set<T> toSet(@Nonnull Iterable<T> source);  }