?????????????????????????????

import java.util.Random;

/**
 * ??????????
 * @Description:

 * @File: Demo4.java

 * @Package None

 * @Author Hanyonglu

 * @Date 2012-10-18 ????06:27:38

 * @Version V1.0
 */
public class Demo4 {
    public static void main(String[] args) {
        int[] values = new int[20];
        Random random = new Random();
      
        for(int i = 0;i < values.length;i++){
            int number = random.nextInt(100) + 1;
          
            for(int j = 0;j <= i;j++){
                if(number != values[j]){
                    values[i]=number;
                }                            
            }
        }
      
        // ???????鰱???????
        for(int i = 0;i < values.length;i++){
            System.out.print(values[i] + " ");
          
            if(( i + 1 ) % 10 == 0){
                System.out.println(" ");
            }
        }
    }
}

????????????????????Ч?????????????????????????????μ???б???????????????????臨?????O(N^2)??????????????????£?????漰?????????????????????HashSet??HashMap??????HashSet???Set????Set????????????????????????????????HashMap???Map???????????????Key????????????????HashMap??HashSet??????

?????????HashMap????????????????key?????????Ok??????′???

import java.util.HashMap;
import java.util.Iterator;
import java.util.Random;
import java.util.Map.Entry;

/**
 * ???HashMap???
 * @Description:

 * @File: Demo.java

 * @Package None

 * @Author Hanyonglu

 * @Date 2012-10-18 ????06:12:50

 * @Version V1.0
 */
public class Demo {
    public static void main(String[] args) {
        int n = 0;
        Object[] values = new Object[20];
      
        Random random = new Random();
        HashMap<Object?? Object> hashMap = new HashMap<Object?? Object>();
      
        // ????????????????HashMap
        for(int i = 0;i < values.length;i++){
            int number = random.nextInt(100) + 1;
            hashMap.put(number?? i);
        }
      
        // ??HashMap????????
        values = hashMap.keySet().toArray();
      
        // ???????鰱???????
        for(int i = 0;i < values.length;i++){
            System.out.print(values[i] + " ");
          
            if(( i + 1 ) % 10 == 0){
                System.out.println(" ");
            }
        }
      
//        Iterator iter = hashMap.entrySet().iterator();
//        // ????HashMap
//        while (iter.hasNext()) {
//            Entry<Integer?? Integer> entry = (Entry)iter.next();
//            int key = entry.getKey();
//            n++;
//          
//            System.out.print(key + " ");
//          
//            if(n % 10 == 0){
//                System.out.println(" ");
//            }
//        }
    }
}