Java examples for java.util:Iterable Convert
Convert Iterable to Set
//package com.java2s; import java.util.Iterator; import java.util.Set; import java.util.TreeSet; public class Main { public static <T> Set<T> toSet(final Iterable<T> iterable) { final Set<T> set = new TreeSet<T>(); for (Iterator<T> i = iterable.iterator(); i.hasNext();) { set.add(i.next());/*from w ww .j a v a 2 s .c o m*/ } return set; } }