java program to remove duplicate words in a string

public static void main(String[] args) {

        String result = removeDup("AAABBBCCC");
        System.out.println(result); // ABC

public static  String  removeDup( String  str) {
        String result = "";
        for (int i = 0; i < str.length(); i++)
            if (!result.contains("" + str.charAt(i)))
                result += "" + str.charAt(i);
        return result;
    }
}

4
7

                                    String fullString = &quot;lol lol&quot;;
String[] words = fullString.split(&quot;\\W+&quot;);
StringBuilder stringBuilder = new StringBuilder();
Set&lt;String&gt; wordsHashSet = new HashSet&lt;&gt;();

for (String word : words) {
    if (wordsHashSet.contains(word.toLowerCase())) continue;
    wordsHashSet.add(word.toLowerCase());
    stringBuilder.append(word).append(&quot; &quot;);
}
String nonDuplicateString = stringBuilder.toString().trim();

4 (7 Votes)
0
3.83
6

                                    String str1 = &quot;ABCDABCD&quot;;
String result1 = &quot;&quot;;

for (int a = 0; a &lt;= str1.length()-1; a++) {
if (result1.contains(&quot;&quot; + str1.charAt(a))) { 
// charAt methodda you provide index number ve sana character olarak donuyor,
// If the string result does not contains str.CharAt(i), 
// then we concate it to the result. if it does we will not
   continue;
}
result1 += str1.charAt(a);
}
System.out.println(result1);

3.83 (6 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
write a program in java to remove duplicate characters in a string Removing Duplicate words JAVA remove duplicate words in java program for removing duplicated words from string java remove duplicate words from string java remove-duplicaterepeated-words-string java java remove duplicates from string until no duplicates java remove duplicates from character array remove duplicate elements from string java how to remove duplicates in array in java remove duplicates in array java remove consecutive duplicates in string java how to remove duplicate characters from string in java remove duplicates from string in java how to remove duplicates arrays in java using methods remove array duplicates java delete duplicates java removing duplicates from astring in java remove duplicate values string function in java remove duplicates in an array java java remove duplicates from string array How to remove duplicate code in java java program to remove repeated characters in a string eliminate duplicates in arrays java how to delete duplicates in java calling method remove duplicate characters from a given string java Write a Java Program to remove all duplicate characters from the given string and return the resultant string. remove duplicates in a string array java remove duplicate from string in java how to remove duplicates from the array in java java remove duplicates in array' Remove duplicate from string remove all duplicate characters from a string in java java program to remove duplicate words in a string remove duplicates string in java remove duplicates in java to remove repeated characters from a string in java remove duplicates java removing duplicate words from string in java removing duplicates from string in java java remove duplicate strings from array how to remove duplicates using methods in java how to remove duplicates in java array remove duplicates java remove duplicates from a string in java java remove duplicates from array remove duplicate string in java write a java program to print after removing duplicates from a given string how to remove duplicate in array java remove duplicate characters in a string in java removing dupilcates in a string in java how to remove duplicate from string remove duplicate characters from string java java code to remove duplicate characters from string in java string remove duplicates remove repeated characters from a string in java how to remove duplicates from an array java remove duplicates from array in java how to remove duplicate from array in java remove duplicates array java remove Duplicate words in string in java how to remove duplicates from array in java remove duplicate from array in java java remove repeated characters from string how to remove duplicates in an array in java java program to remove duplicates remove duplicate words from string in java remove dupliacte from string java remove duplicates string java sort method in java remove duplicates remove duplicates in string java remove duplicate characters from string remove duplicates in string java remove duplicates from given string in java remove duplicate in string how to remove the duplicate character from String how to remove duplicates in a string java 8 how to remove duplicates in a string java remove duplicate string collection in java remove duplicate array in java remove duplicate in java how to remove duplicate values in string array in java remove duplicates from string java java remove duplicate words from array remove duplicates from array java remove duplicates from string array java how to delete all duplicate characters from string in java how to delete duplicate characters in a string using string builder in java String remove duplicate method in java String remove duplicate in java remove duplicates word from string java how to remove duplicate from a string in java how to remove the duplicate character from String? how to remove duplicates in string array java remove duplicates from string java using for loop remove duplicate characters in a string java java remove duplicates from string remove duplicated characters from a string java java program to remove duplicate words in given string how to remove duplicate words in a sentence using java java program to remove duplicate words in a sentence java remove duplicate words from string java code to remove duplicate words in a string
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source