  public static Integer[] eliminateDuplicate(int[] a) {        if (a == null) {            throw new NullPointerException();        }        List<Integer> list = new ArrayList<Integer>();        for (int i = 0; i < a.length; i++) {            // include last element by default, if not the last element, do the check for duplication.            if (i == a.length - 1 || a[i] != a[i + 1]) {                list.add(a[i]);            }        }        return list.toArray(new Integer[0]);    }
Eliminating duplicates in an array of ints
java;array
Your function doesn't handle duplicates in the entire array, but only in consecutive entries.  A better name might be collapseConsecutive.The input is an int[], but the return type is Integer[].  Consistency would be nice.You don't need to throw NullPointerException explicitly.  If a is null, then a NullPointerException will automatically be thrown when it tries to do a.length.  If you really want to explicitly validate your arguments, you could throw IllegalArgumentException instead.A micro-optimization would be to change toif (i == 0 || a[i] != a[i - 1]) {    list.add(a[i]);}Comparing against 0 is simpler than comparing against a.length - 1 since the JVM (and CPUs) has an ifeq opcode for doing just that.  To compare against a.length - 1, the bytecode would have to load a.length - 1 into a register before comparing  and that is assuming that the compiler is smart enough to compute a.length - 1 just once.