Code example for Set

Methods: sizetoArray

public class CollectionUtils { 
	public static String getTheOnlyElementOf(Set<String> set) { 
		if (set.size() != 1) { 
			throw new RuntimeException("Expected a set of one element"); //$NON-NLS-1$ 
		return set.toArray(new String[1])[0]; 
	public static Set<String> asSet(String... strs) { 
		return new HashSet<String>(Arrays.asList(strs)); 
	public static Object[] collectionToSortedArray(Collection<? extends Object> objects) { 
		Object[] sortedArray = objects.toArray(new Object[] {}); 
		Arrays.sort(sortedArray, new Comparator<Object>() { 
Stop searching for code, let great code find you!  Add Codota to your java IDE