on 11-21-2006 2:25 PM
Hi, I need to remove duplicates from my String[] array. Any ideas?
Hi Rune,
Loop through your array values, and compare the ith value and i+1 value and set a flag if it is a duplicate value is found, write out the resultset based on the condition check of the flag.
Something like this.
for(int i=0 ; i< a.length ; i++)
{
for(int j=1;j< a.length; j++)
{
if( a<i> == a[j])
set flag=x; // initialize the flag to some value inside the first for loop
.
.
.
}
}
Try this logic with the right condition check to set the flag value, it will work.
Regards,
Chandra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HashSet hs=new HashSet();
for(int i=0;i<Str.length;i++)
hs.add(Str<b>[i</b>]);
String result[]=new String[hs.size()];
for(int j=0;j<result.length;j++)
result[j]=(String)hs.get(j);
try this...
Regards,
Jai Shankar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.