Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find duplicate string from an Array of String [duplicate]

Tags:

java

I have an array of string, which holds the list of strings. I want to figure out is there any duplicate entries in this list. Basically i have a list of users, and there should be no duplicate entries.

like image 757
mdashu Avatar asked Mar 12 '13 09:03

mdashu


1 Answers

you can add the String array to the HashSet

Set<String> h = new HashSet<String>(Arrays.asList(new String[] { "a", "b" }));

this will get you unique String values. If necessary convert the HashSet back to array

String[] uniqueValues = h.toArray(new String[0]);
like image 92
codeMan Avatar answered Sep 19 '22 01:09

codeMan