Remove the dublicate word from string
public class HelloWorld{
public static void main(String []args){
String str = "Welcome to geeks for geeks";
int count;//if same word milga to skip karna ka lia count++ karna pada ga
String[] words = str.split("\\W");
for(int i = 0;i<words.length;i++){
count = 1;
for(int j = i+1;j<words.length;j++){
if(words[i].equalsIgnoreCase(words[j])){
count++;
// words[j]="";
}
}
if(count==1 && words[i] != "")
System.out.println(words[i]);
}
}
}
Comments
Post a Comment