java program to remove duplicate words in a string

Solutions on MaxInterview for java program to remove duplicate words in a string by the best coders in the world

showing results for - "java program to remove duplicate words in a string"
Marlene
16 Oct 2019
1public static void main(String[] args) {
2
3        String result = removeDup("AAABBBCCC");
4        System.out.println(result); // ABC
5
6public static  String  removeDup( String  str) {
7        String result = "";
8        for (int i = 0; i < str.length(); i++)
9            if (!result.contains("" + str.charAt(i)))
10                result += "" + str.charAt(i);
11        return result;
12    }
13}
Cristina
16 May 2019
1String fullString = "lol lol";
2String[] words = fullString.split("\\W+");
3StringBuilder stringBuilder = new StringBuilder();
4Set<String> wordsHashSet = new HashSet<>();
5
6for (String word : words) {
7    if (wordsHashSet.contains(word.toLowerCase())) continue;
8    wordsHashSet.add(word.toLowerCase());
9    stringBuilder.append(word).append(" ");
10}
11String nonDuplicateString = stringBuilder.toString().trim();
Margaux
08 Mar 2019
1String str1 = "ABCDABCD";
2String result1 = "";
3
4for (int a = 0; a <= str1.length()-1; a++) {
5if (result1.contains("" + str1.charAt(a))) { 
6// charAt methodda you provide index number ve sana character olarak donuyor,
7// If the string result does not contains str.CharAt(i), 
8// then we concate it to the result. if it does we will not
9   continue;
10}
11result1 += str1.charAt(a);
12}
13System.out.println(result1);
queries leading to this page
how to remove duplicates in string array javahow to remove duplicate words in a sentence using javaremove duplicates from string array javahow to remove duplicates using methods in javahow to delete all duplicate characters from string in javaremove duplicates from array in javato remove duplicates from array in javahow to remove duplicate from a string in javato remove repeated characters from a string in javajava program to remove duplicate words in a stringprogram for removing duplicated words from string javajava remove duplicate words from arrayhow to remove duplicates from array in javajava remove duplicates in array 27remove repeated characters from a string in javadelete duplicates javaremove duplicate characters in a string in javaremove duplicates in string javaremoving duplicates from astring in javaremoving duplicate stringremove all duplicate characters from a string in javajava remove duplicate from arrayhow to remove duplicates from an array in javaremove duplicates from string in javaremoving dupilcates in a string in javaremove duplicate words from string javahow to remove duplicates from an array javahow to remove duplicates in string javaremove duplicates string in javahow to remove duplicate words in javajava remove duplicate words from stringremove duplicates from a string in javajava remove duplicatesremove duplicate in javaremove duplicates word from string javaremoving duplicate words from a string in javaremove array duplicates javaremove duplicate elements from string javajava remove duplicate strings from arrayhow to delete duplicates in java calling methodremove duplicate words in string in javaremove duplicates in an array javaremoving duplicates from string in javajava strings remove duplicate charactersjava remove repeated characters from stringhow to remove duplicate characters from string in javaremove duplicates from given string in javadelete duplicates in array javaremove duplicates from character array in javaremove duplicates from array java in orderremove duplicate words from string in javaremove duplicates in string in javahow to remove duplicate in array javaremove duplicates in a string array javastring remove duplicate method in javaremove duplicate from string in javajava remove duplicates from string arrayremove duplicates java arrayremove duplicate string in javaremove duplicaterepeated words string javaremove duplicate in a a stringhow to remove duplicate code in javaremove duplicates in string array javaremove duplicates in javajava program to remove duplicatesjava remove duplicates from character arrayarray remove duplicates java remove duplicate characters from string in javajava string remove duplicate characterseliminate duplicates in arrays javajava code to remove duplicate characters from string in javahow to remove the duplicate character from stringhow to remove duplicate values in string array in java 8string remove duplicate in javajava remove duplicates from stringhow to remove duplicates in array in javahow to remove the duplicates from array in javaremove duplicate from array in javahow to remove the duplicate character from string 3fjava array remove duplicatesstring remove duplicatesremove duplicate characters in a string javaremove the duplicate elements in string in javaprogram to delete all repeated words in string in javaremoving a duplicate character in a string java method remove dupliacte from string javajava remove duplicates from string until no duplicatesremove duplicate words in javaremove duplicate array in javajava remove duplicates from arrayremove duplicate substring from string in javaremove duplicates from array javajava program to remove repeated characters in a stringremove duplicates in array javaremove duplicates string from array javahow to remove duplicates from the array in javaremove duplicates string javahow to remove duplicates in an array in javahow to remove duplicates in string in javaduplicate removal in sorted array javajava code to remove duplicate words in a stringdelete repeated characters in a string javaremove duplicate java easyremove duplicate characters in a stringremove consecutive duplicates in string javahow to remove duplicates in a string javaremove duplicates in stringhow to remove duplicate values in string array in javaremove duplicates from string java using for loophow to remove duplicates in a string java 8remove duplicated characters from a string javaremove duplicates words from string javahow to get rid of duplicates in javaremove duplicate characters from string javahow to remove duplicates arrays in java using methodshow to remove duplicate from stringremove duplicates javaremoving duplicate words javaremove duplicate values string function in javahow to delete duplicate characters in a string using string builder in javawap to remove duplicates from an unsorted array of strings in javahow to remove duplicates in javaremove duplicate characters from a given string javadelete redundant letter string javaremove repeated characters in a string in javawrite a java program to remove all duplicate characters from the given string and return the resultant string remove duplicate from stringremove duplicate in java stringremove duplicates array javawrite a java program to print after removing duplicates from a given stringhow to remove duplicate from array in javahow to remove repeated characters in string in javajava program to remove duplicate words in given stringremove duplicates in string javaremove duplicates using stream javajava remove duplicate characters from stringjava program to remove duplicate words in a sentenceremove duplicates from string javahow to remove duplicates from an array of strings in javaremove duplicate in string remove duplicate number from string javaremove duplicate characters in java stringremove duplicate letters from a string in javajava code for remove duplactes from stringwrite a program in java to remove duplicate characters in a stringremoving duplicate words from string in javasort method in java remove duplicates remove duplicate string collection in javajava program to remove duplicate words in a string