Android Collection Sub Collection Get subset(Collection c, int size, java.util.Random rand)

Here you can find the source of subset(Collection c, int size, java.util.Random rand)

Description

subset

License

Open Source License

Declaration

public static Collection subset(Collection c, int size,
            java.util.Random rand) 

Method Source Code

//package com.java2s;
/* Copyright (C) 2003 Univ. of Massachusetts Amherst, Computer Science Dept.
 This file is part of "MALLET" (MAchine Learning for LanguagE Toolkit).
 http://www.cs.umass.edu/~mccallum/mallet
 This software is provided under the terms of the Common Public License,
 version 1.0, as published by http://www.opensource.org.  For further
 information, see the file `LICENSE' included with this distribution. */

import java.util.*;

public class Main {
    public static Collection subset(Collection c, int size,
            java.util.Random rand) {
        ArrayList list = new ArrayList(c);
        int realSize = (size < c.size()) ? size : c.size();
        java.util.Collections.shuffle(list, rand);
        return list.subList(0, realSize);
    }//from w  ww  .j  av  a 2s . c o  m
}