Java tutorial
//package com.java2s; //License from project: Apache License import java.util.HashSet; import java.util.Set; public class Main { /** * Select the given number of elements from the given set. * * @param <T> encapsulated type * @param set set * @param count number of elements to retrieve * @return set */ public static <T> Set<T> selectSome(Set<T> set, int count) { Set<T> newSet = new HashSet<T>(); int i = 0; for (T each : set) { if (++i > count) { break; } newSet.add(each); } return newSet; } }