Example usage for java.util Set toArray

List of usage examples for java.util Set toArray

Introduction

In this page you can find the example usage for java.util Set toArray.

Prototype

<T> T[] toArray(T[] a);

Source Link

Document

Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.

Usage

From source file:Main.java

public static String[] clean(String[] input) {
    Set<String> unique = new TreeSet<>(Arrays.asList(input));
    return unique.toArray(new String[unique.size()]);
}

From source file:Main.java

public static String[] toArray(Set<String> set) {
    return set.toArray(new String[set.size()]);
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <E extends Object> E[] toArray(Set<E> set, Class<E> clazz) {
    return set.toArray((E[]) Array.newInstance(clazz, set.size()));
}

From source file:Main.java

private static boolean isList(Map temp) {
    Set s = new TreeSet(temp.keySet());
    Object[] keyArray = s.toArray(new Object[] {});
    for (int i = 0; i < keyArray.length; i++) {
        if (keyArray[i] instanceof Number) {
            if (((Number) keyArray[i]).intValue() != i) {
                return false;
            }/* w w  w.  j av a  2 s  .  co m*/
        } else {
            return false;
        }
    }
    return true;
}

From source file:org.atemsource.atem.impl.EntityTypeUtils.java

public static String[] convertToArray(final Set<String> selectableTypeCodes) {
    return selectableTypeCodes.toArray(new String[selectableTypeCodes.size()]);
}

From source file:Main.java

/**
 * Function to remove duplicate elements from the array of string
 * @param stringArray array of string having duplicate elements.
 * @return unique array of string /*from  ww w.  j ava2  s. co m*/
 */
public static String[] removeDuplicatesFrom(String[] stringArray) {
    Set<String> temp = new HashSet<String>(Arrays.asList(stringArray));
    String[] uniqueStringArray = temp.toArray(new String[temp.size()]);
    return uniqueStringArray;
}

From source file:com.tealcube.minecraft.bukkit.mythicdrops.utils.ChatColorUtil.java

public static ChatColor getRandomChatColorFromSet(Set<ChatColor> chatColors) {
    ChatColor[] chatColors1 = chatColors.toArray(new ChatColor[chatColors.size()]);
    return chatColors1[RandomUtils.nextInt(chatColors1.length)];
}

From source file:Main.java

public static byte[][] toArray(Set<byte[]> set) {
    if (set == null || set.size() == 0)
        return new byte[0][];

    return set.toArray(new byte[set.size()][]);
}

From source file:main.java.utils.Permutation.java

public static Set<IntPair> getPermutations(Set<Integer> list) {
    Set<IntPair> permutations = new HashSet<IntPair>();

    int[] array = ArrayUtils.toPrimitive(list.toArray(new Integer[list.size()]));

    for (int i = 0; i < array.length; i++)
        for (int j = i + 1; j < array.length; j++)
            permutations.add(new IntPair(array[i], array[j]));

    return permutations;
}

From source file:Main.java

public static String getTheOnlyElementOf(Set<String> set) {
    if (set.size() != 1) {
        throw new RuntimeException("Expected a set of one element"); //$NON-NLS-1$
    }//  ww  w . jav  a 2  s.  co  m
    return set.toArray(new String[1])[0];
}