Java tutorial
//package com.java2s; /* * File: CollectionUtil.java * Authors: Justin Basilico * Company: Sandia National Laboratories * Project: Cognitive Foundry * * Copyright March 25, 2008, Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the U.S. Government. Export * of this program may require a license from the United States Government. * See CopyrightHistory.txt for complete details. * */ import java.util.LinkedHashSet; public class Main { /** The default load factor for a hash map is {@value}. */ private static final float DEFAULT_LOAD_FACTOR = 0.75f; /** * 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. * * @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); } }