How can I remove duplicate strings from a string array without using a HashSet?
I try to use loops, but the words not delete.
StringBuffer outString = ne
If you are allowed to use List
s, you can define a generic method that does this fairly easily:
public T[] removeDuplicates(final T[] array) {
List noDuplicates = new ArrayList();
for (T arrayElem : array) {
if (!noDuplicates.contains(arrayElem)) {
noDuplicates.add(arrayElem);
}
}
return (T[]) noDuplicates.toArray();
}