|
|
题目来自于论坛:http://topic.csdn.net/u/20081012/14/3cc93688-1f7f-4985-806c-3f729c78261b.html
不过我使用的是TreeSet,因为题目要求是集合
<div class="highlighter">
- public static void test2() {
- TreeSet<Integer> a = new TreeSet<Integer>();
- TreeSet<Integer> b = new TreeSet<Integer>();
- Random r = new Random();
- for (int i = 0; i < 30; i++) {
- a.add(r.nextInt(30));
- b.add(r.nextInt(30));
- }
- a.retainAll(b);
- System.out.println(a);
- System.out.println(b);
- System.out.println(a);
- }
|
|