- public class demo {
- public static void main(String[] args) {
- HashSet<Integer> hs = getRandom();
- System.out.println(hs.toString());
- }
- public static HashSet<Integer> getRandom() {
- Random r = new Random();
- HashSet<Integer> hs = new HashSet<Integer>();
- while(hs.size()<10){
- hs.add(r.nextInt(20)+1);
- }
- return hs;
- }
- }
复制代码 |
|