# Question with duplication words

**URL:** <https://discourse.processing.org/t/question-with-duplication-words/29511>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [April 20, 2021, 3:37am UTC](https://discourse.processing.org/t/question-with-duplication-words/29511 "2021-04-20T03:37:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pokeyace](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@Pokeyace](https://discourse.processing.org/u/Pokeyace)\
**Post date:** [April 20, 2021, 3:37am UTC](https://discourse.processing.org/t/question-with-duplication-words/29511/1 "2021-04-20T03:37:30Z")

</div>

String S;  
int L, i, j;  
String W[];  
boolean build;

void setup(){  
// Initializations  
S = “We are the world We are the children”;  
L = S.length();  
j = 0;  
W = new String[100];  
W[0] = “”;  
// Main loop  
for(i = 0; i \< L; i++){  
if(S.charAt(i) == ’ '){  
if(build == true){  
j++;  
W[j] = “”;  
build = false;  
}  
}  
else{  
W[j] = W[j] + S.charAt(i);  
build = true;  
}  
}  
if(build == true)  
j++;  
for(i = 0; i \< j; i++)  
println(W[i]);  
println(j);  
}

what else should I add to prevent the word “We are the world we are the children being duplicated?”  
Do I have to use HashSet uniques = new HashSet();?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 20, 2021, 7:32am UTC](https://discourse.processing.org/t/question-with-duplication-words/29511/2 "2021-04-20T07:32:36Z")

</div>

> [@Pokeyace](#):
>
> prevent the word “We are the world we are the children being duplicated?”

Please elaborate

What’s your goal?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 20, 2021, 9:50am UTC](https://discourse.processing.org/t/question-with-duplication-words/29511/4 "2021-04-20T09:50:54Z")

</div>

using HashMap seems a good idea

see reference

---

<div class="post-metadata">

**Author:** ![Pokeyace](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@Pokeyace](https://discourse.processing.org/u/Pokeyace)\
**Post date:** [April 21, 2021, 4:21am UTC](https://discourse.processing.org/t/question-with-duplication-words/29511/5 "2021-04-21T04:21:03Z")

</div>

The question is “To create a program that will start with a sentence, parse the sentence, and then display a sorted list of the words in the sentence with duplicate words removed.”

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 21, 2021, 4:24am UTC](https://discourse.processing.org/t/question-with-duplication-words/29511/6 "2021-04-21T04:24:36Z")

</div>

Okay

W is your list that you built

For loop W and take only new words into list W2  
using Hashmap

Sort W2

---

<div class="post-metadata">

**Author:** ![Pokeyace](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@Pokeyace](https://discourse.processing.org/u/Pokeyace)\
**Post date:** [April 21, 2021, 4:26am UTC](https://discourse.processing.org/t/question-with-duplication-words/29511/8 "2021-04-21T04:26:28Z")

</div>

I was never show how to use hashmap

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [April 21, 2021, 4:48am UTC](https://discourse.processing.org/t/question-with-duplication-words/29511/9 "2021-04-21T04:48:34Z")

</div>

Use a StringList container:  
[Processing.org/reference/StringList.html](http://Processing.org/reference/StringList.html)

It’s got useful methods such as **sort()** & **appendUnique()**:  
[Processing.org/reference/StringList\_sort\_.html](http://Processing.org/reference/StringList_sort_.html)

[Processing.GitHub.io/processing-javadocs/core/processing/data/StringList.html#appendUnique-java.lang.String-](http://Processing.GitHub.io/processing-javadocs/core/processing/data/StringList.html#appendUnique-java.lang.String-)
