- import java.util.*;
- class Test
- {
- public static void main(String[] args)
- {
- // Integer[] arr = new Integer[]{4,2,4,6,1,2,4,7,8};
- Character [] arr = new Character[]{'a','b','c','a','d','c','e'};
- print(arr);
- print(originalRe(arr));
- }
- public static <T> Object [] originalRe(T [] arr)
- {
- ArrayList<T> alist = new ArrayList<T>();
- for(T t : arr)
- {
- if(!alist.contains(t))
- alist.add(t);
- }
- return alist.toArray();
- }
- public static <T> void print(T [] arr)
- {
- StringBuilder sb = new StringBuilder();
- sb.append("{");
- for(T a : arr)
- {
- sb.append(a+", ");
- }
- sb.replace(sb.length()-2, sb.length(), "}");
- System.out.println(sb.toString());
- }
- }
复制代码 |