方案1:
用set也很容易的
- public static void main(String[] args) {
- int[] nums = { 5, 6, 6, 6, 8, 8, 7 };
- List<Integer> numList = new ArrayList<Integer>();
- for (int i : nums)
- numList.add(i);
- Set<Integer> numSet = new HashSet<Integer>();
- numSet.addAll(numList);
- System.out.println(numSet);
- }
方案2:
[java]
- public static void main(String[] args) {
- String[] s = {"1","10","15","14","111","133","12","13","1","13"};
- List<String> l = new ArrayList<String>();
- for(String a:s){
- if(!l.contains(a)){
- l.add(a);
- }
- }
- System.out.println(l);
- }