Here you can find the source of eraseDuplicatedValue(String[] srcArr)
Parameter | Description |
---|---|
srcArr | a parameter |
public static String[] eraseDuplicatedValue(String[] srcArr)
//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; } }