Question with duplication words

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();?

Please elaborate

What’s your goal?

using HashMap seems a good idea

see reference

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.”

Okay

W is your list that you built

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

Sort W2

I was never show how to use hashmap

Use a StringList container:
Processing.org/reference/StringList.html

It’s got useful methods such as sort() & appendUnique():
Processing.org/reference/StringList_sort_.html

Processing.GitHub.io/processing-javadocs/core/processing/data/StringList.html#appendUnique-java.lang.String-