publicclassMain{ publicstaticvoidmain(String[] args){ Scanner in = new Scanner(System.in); for (; in.hasNext();) { int n = in.nextInt(); int[] a = newint[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } Arrays.sort(a); List<Integer> list = new ArrayList<>(); // dedupe for (int i = 0; i < n; i++) { list.add(a[i]); int j = i + 1; for (; j < n && a[j] == a[i]; ++j); i = j - 1; } for (Integer each : list) { System.out.println(each); } } } }
publicclassMain{ publicstaticvoidmain(String[] args){ Scanner in = new Scanner(System.in); for (; in.hasNext();) { int n = in.nextInt(); Set<Integer> ordSet = new TreeSet<>(); for (int i = 0; i < n; i++) { ordSet.add(in.nextInt()); } for (Iterator iter = ordSet.iterator(); iter.hasNext();) { System.out.println(iter.next()); } } } }