List of utility methods to do Array Duplicate
String[] | addNoDuplicate(String[] array, String target) add No Duplicate List<String> list = Arrays.asList(array); if (!list.contains(target)) { list.add(target); String[] result = list.toArray(new String[0]); return result; |
byte[] | arrayDuplicate(byte[] in) array Duplicate byte[] out = new byte[in.length]; arrayCopy(out, 0, in); return out; |
int[] | deleteDuplicatedPages(int[] pages) Transforms (0,1,2,2,3) to (0,1,2,3) List<Integer> result = new ArrayList<Integer>(); int lastInt = -1; for (Integer currentInt : pages) { if (lastInt != currentInt) { result.add(currentInt); lastInt = currentInt; int[] arrayResult = new int[result.size()]; for (int i = 0; i < result.size(); i++) { arrayResult[i] = result.get(i); return arrayResult; |
String[] | duplicateArrayEntries(String[] inputArr, int numDuplicates) duplicate Array Entries List<String> list = new ArrayList<String>(); for (String d : inputArr) { for (int i = 0; i < numDuplicates; i++) { list.add(d); return list.toArray(new String[0]); |
String[] | eraseDuplicatedValue(String[] srcArr) Erase Duplicated method List tempVector = new ArrayList(); int loopCount = 0; for (loopCount = 0; loopCount < srcArr.length; loopCount++) { tempVector.add(srcArr[loopCount]); Collections.sort(tempVector); for (loopCount = 0; loopCount < srcArr.length; loopCount++) { srcArr[loopCount] = (String) (tempVector.get(loopCount)); ... |
boolean | hasDuplicates(final T[] array) Determines whether a given array contains duplicate values. if (array == null) { throw new IllegalArgumentException(); for (int i = 0; i < array.length - 1; i++) { final T x = array[i]; for (int j = i + 1; j < array.length; j++) { final T y = array[j]; if (x.equals(y)) { ... |
boolean | isDuplicated(String[] strArray) Check if there are duplicated values in a string array Set<String> strSet = new HashSet<String>(); for (int i = 0; i < strArray.length; i++) { strSet.add(strArray[i]); return (strSet.size() < strArray.length) ? true : false; |
double[] | removeDuplicates(double[] array) remove Duplicates double[] result = null; Map<Double, Object> values = new HashMap<Double, Object>(array.length); for (double value : array) values.put(value, new Object()); int i = 0; result = new double[values.size()]; for (double value : values.keySet()) ... |
Object[] | removeDuplicates(final Object[] array) Remove duplicate objects from an array if (isNull(array)) { return null; try { List listNewPks = new ArrayList(); listNewPks.addAll(new LinkedHashSet(Arrays.asList(array))); return listNewPks.toArray(); } catch (Exception e) { ... |
int[] | removeDuplicates(int[] input) Remove duplicate elements from an int array if (input.length < 2) { return input; Arrays.sort(input); int j = 0; int i = 1; while (i < input.length) { if (input[i] == input[j]) { ... |