List of usage examples for java.util LinkedHashSet LinkedHashSet
public LinkedHashSet(int initialCapacity, float loadFactor)
From source file:Main.java
public static void main(String[] args) { LinkedHashSet linkedHashSet = new LinkedHashSet(10, 0.75F); linkedHashSet.add("1"); linkedHashSet.add("2"); linkedHashSet.add("java2s.com"); Object[] objArray = linkedHashSet.toArray(); System.out.println(Arrays.toString(objArray)); }
From source file:Main.java
/** * Creates a new {@link LinkedHashSet} with the given expected size. It uses the * default load factor (0.75) to estimate the proper number of elements for * the data structure to avoid a rehash or resize when the given number of * elements are added.//from w w w. ja v a2 s .c o m * * @param <ValueType> * The type of the value in the set. * @param size * The size. Must be positive. * @return * A new hash map with the given expected size. */ public static <ValueType> LinkedHashSet<ValueType> createLinkedHashSetWithSize(final int size) { final int initialCapacity = (int) Math.ceil(size / DEFAULT_LOAD_FACTOR); return new LinkedHashSet<ValueType>(initialCapacity, DEFAULT_LOAD_FACTOR); }
From source file:Main.java
/** * Creates a <code>LinkedHashSet</code> of the optimal hash capacity for given * maximum size and the load factor./*from w w w . jav a 2 s .co m*/ * * @param <E> the element type * * @param size maximum size of the collection * @param loadFactor usage percentage before a rehash occurs. Default value for * Collections framework is 0.75. Lower values result in less * chance of collisions at the expense of larger memory footprint * @return the created <code>LinkedHashSet</code> */ public static <E> LinkedHashSet<E> createLinkedHashSet(int size, float loadFactor) { return new LinkedHashSet<E>(calcHashCapacity(size, loadFactor), loadFactor); }
From source file:Main.java
/** * Creates the linked hash set instance that will hold the given amount of elements. The returned instance is * optimized for that size and will not grow until the given number of elements are added. * <p>/*from w ww .ja va 2 s . co m*/ * The method is same as <code>new LinkedHashSet<V>((int) (size * 1.1), 0.95f)</code> * * @param <V> * the value type * @param size * the preferred size * @return the map instance */ public static <V> Set<V> createLinkedHashSet(int size) { return new LinkedHashSet<>((int) (size * SIZE_NORMALIZATION), LOAD_FACTOR); }