Java Array Duplicate eraseDuplicatedValue(String[] srcArr)

Here you can find the source of eraseDuplicatedValue(String[] srcArr)

Description

Erase Duplicated method

License

Open Source License

Parameter

Parameter Description
srcArr a parameter

Return

String[]

Declaration

public static String[] eraseDuplicatedValue(String[] srcArr) 

Method Source Code

//package com.java2s;

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

public class Main {
    /**// w  w  w.  ja va2 s  . com
     * Erase Duplicated method
     * @param srcArr
     * @return String[]
     */
    public static String[] eraseDuplicatedValue(String[] srcArr) {
        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));
        }

        tempVector.clear();

        tempVector.add(srcArr[0]);

        for (loopCount = 1; loopCount < srcArr.length; loopCount++) {
            if (!srcArr[loopCount].equals(srcArr[loopCount - 1])) {
                tempVector.add(srcArr[loopCount]);
            }
        }

        String[] resultStrArr = new String[tempVector.size()];

        for (loopCount = 0; loopCount < resultStrArr.length; loopCount++) {
            resultStrArr[loopCount] = (String) (tempVector.get(loopCount));
        }
        return resultStrArr;
    }
}

Related

  1. addNoDuplicate(String[] array, String target)
  2. arrayDuplicate(byte[] in)
  3. deleteDuplicatedPages(int[] pages)
  4. duplicateArrayEntries(String[] inputArr, int numDuplicates)
  5. hasDuplicates(final T[] array)
  6. isDuplicated(String[] strArray)
  7. removeDuplicates(double[] array)
  8. removeDuplicates(final Object[] array)