/    Sign up×
Community /Pin to ProfileBookmark

Deleting duplicate strings from one/two array string(s)

I want to delete duplicate strings from an array string.

And also need to delete duplicate strings from two array strings.

to post a comment
Java

2 Comments(s)

Copy linkTweet thisAlerts:
@Frankie_CWRUJul 05.2006 — I Think that this is what you are trying to do:

for(int i = 0; i < a.length; i++)

for(int j = 0; j < b.length; j++){

if(a[i].equals(b[j])

b[j] = "";

if(a[i].equals(a[j])

a[j] = "";

}





Then you can shift all of the strings that are still valid into a new array of the appropriate length.
Copy linkTweet thisAlerts:
@Mr__RamauthorJul 06.2006 — Thanks for response.

[U]I have written like this[/U] :-

// Deleting Duplicate Names from TO/CC list - RAM

public String[] deleteDuplicates(String[] strs)

{

java.util.ArrayList nodups = new java.util.ArrayList() ;

for(int i = 0 ; i < strs.length ; i++)

{

if( (!nodups.contains(strs[i])) && (!strs[i].equals("")) )

nodups.add(strs[i]);

}



strs = (String[])nodups.toArray(new String[nodups.size()]);



return(strs);

}



// Deleting Duplicate Names from TO & CC list.

// If duplicate find, removing it from CC.



public String[] deleteDuplicates(String[] str, String[] strs)

{

java.util.ArrayList nodups = new java.util.ArrayList() ;



boolean dupfound;



for(int i=0; i<strs.length; i++)

{

dupfound = false;



for(int j=0; j<str.length; j++)

{

if(strs[i].equals(str[j]))

{

dupfound = true;

break;

}

}

if(dupfound == false)

nodups.add(strs[i]);

}



strs = (String[])nodups.toArray(new String[nodups.size()]);



return(strs);

}
×

Success!

Help @Mr__Ram spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...