RemoveDuplicates { public int removeDuplicates(int[] nums) { int newLen = 0; if (nums.length > 0) { int pos = 0; int current = nums[pos++]; newLen = 1; while (pos < nums.length) { if (nums[pos] != current) { nums[newLen++] = nums[pos]; current = nums[pos]; } pos++; } } return newLen; }  int removeDuplicates(int[] nums); int removeDuplicatesAtMostTwice(int[] nums);  }
@Test(dataProvider = "removeAllDuplicatesObjects") public void testRemoveDuplicates(int[] array, int[] expected) { int len = new RemoveDuplicates().removeDuplicates(array); int[] actual = IntStream.of(array).limit(len).toArray(); assertEquals(actual, expected); }