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){
W[j] = “”;
build = false;
W[j] = W[j] + S.charAt(i);
build = true;
if(build == true)
for(i = 0; i < j; i++)

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


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:

It’s got useful methods such as sort() & appendUnique():