删除数组中的重复元素

方案1:

 

用set也很容易的
 
  1. public static void main(String[] args) {  
  2.        int[] nums = { 5666887 };  
  3.        List<Integer> numList = new ArrayList<Integer>();  
  4.        for (int i : nums)  
  5.            numList.add(i);  
  6.        Set<Integer> numSet = new HashSet<Integer>();  
  7.        numSet.addAll(numList);  
  8.        System.out.println(numSet);  
  9.    }  
 

方案2:

[java] 
  1. public static void main(String[] args) {  
  2.         String[] s = {"1","10","15","14","111","133","12","13","1","13"};  
  3.         List<String> l = new ArrayList<String>();  
  4.         for(String a:s){  
  5.             if(!l.contains(a)){  
  6.                 l.add(a);  
  7.             }  
  8.         }  
  9.         System.out.println(l);  
  10.     }  

posted on 2012-08-19 19:40  AllenZhao  阅读(151)  评论(0编辑  收藏  举报

导航