A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
java.util.Map - remove random elements
Joined: Apr 19, 2006
Apr 16, 2009 11:56:38
I have SortedMap and need to remove a given number of elements from there in random order (i.e. it doesn't matter which elements will be removed, but they should be random)
Do you have any idea of how to do that in effective way?
Joined: Jan 17, 2006
Apr 16, 2009 12:27:43
Dump all the keys into a List; Pick a random element from the List; remove the corresponding mapping fromt he Map
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
subject: java.util.Map - remove random elements
A time complexity question
DOM vs SAX
removing a row from an array
Random array string that doesn't repeat
Basic Question For JList
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015