commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hernan Silberman <hsilb...@pdi.com>
Subject [Collections] Random iterator?
Date Wed, 02 Mar 2005 18:27:06 GMT

In my unit and load tests, I often find myself retrieving a collection of 
objects from a service, and selecting a random one from the collection.  Seems 
like a common use case (for testing anyhow) and I don't think there's any 
support in java.util Collections for, say, fetching a random item out of a Set.  
It's easy enough to code by hand, but I was wondering if it's already done 
somewhere in commons-collections.  A Random iterator would be really cool.

I suppose:

List theList = new ArrayList( someCollection );
Collections.shuffle( theList );
Iterator theIt = theList.iterator();

works fine too..

thnx...
hernan


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message