importjava.util.ArrayList; importjava.util.List; public class RemoveNumber { public static void main(String[] args) { int[] arr = { 4, 2, 4, 6, 1, 2, 4, 7, 8 }; List<Integer> list = new ArrayList<Integer>(); System.out.println("原有数组是"); for (Integer integer : arr) { list.add(integer); System.out.print(integer + " "); } System.out.println(); for (int i = 0; i < list.size() - 1; i++) { for (int j = i+1; j < list.size(); j++) { if (list.get(i) == list.get(j)) { list.remove(j); j--; } } } Integer[] in = list.toArray(new Integer[list.size()]); System.out.println("目标数组是"); for (Integer i : in) { System.out.print(i + " "); } System.out.println(); } } |