Java Utililty Methods HashSet Create

List of utility methods to do HashSet Create

Description

The list of methods to do HashSet Create are organized into topic(s).

Method

HashSetasHashSet(@SuppressWarnings("unchecked") T... elements)
Create a hashed set from an array.
HashSet<T> result = new HashSet<T>();
Collections.addAll(result, elements);
return result;
HashSetasHashSet(Set set)
as Hash Set
if (HashSet.class.isInstance(set)) {
    return (HashSet<E>) set;
} else {
    return new HashSet<E>(set);
SetasHashSet(T... elements)
as Hash Set
Set<T> set = new HashSet<T>();
Collections.addAll(set, elements);
return set;
String[]convertHashSetIntoArray(HashSet cdsidsSet)
Eliminate duplicate CDSIDs
String[] cdsids = new String[cdsidsSet.size()];
if (cdsidsSet.size() > 0) {
    Iterator it = cdsidsSet.iterator();
    int x = 0;
    while (it.hasNext()) {
        cdsids[x++] = (String) it.next();
return cdsids;
SetcreateHashSet(T... arr)
create Hash Set
int size = arr == null ? 0 : arr.length;
Set<T> set = new HashSet<T>(size);
if (arr != null && arr.length > 0) {
    Collections.addAll(set, arr);
return set;
HashSethashSet()
hash Set
return new HashSet<>();
SethashSet()
Creates an empty HashSet instance.
return new HashSet<T>();
int[]hashset_to_int_array(Set hs)
hashsetinarray
int array[] = new int[hs.size()];
Iterator<Integer> itr = hs.iterator();
int i = 0;
while (itr.hasNext()) {
    array[i++] = Integer.parseInt(itr.next().toString());
return array;
SethashSetFromArray(final T[] objs)
hash Set From Array
final Set<T> set = new HashSet<T>();
for (final T obj : objs) {
    set.add(obj);
return set;
SethashSetOf(T... elements)
hash Set Of
HashSet<T> set = new HashSet<>();
for (T element : elements) {
    set.add(element);
return set;