remove duplicate words from string in java

import java.util.*;
import java.lang.*;
class Demo{
public static void main(String[] args){
String sen = “Sam went went to to to his business”;
String[] arr = sen.split(” “);
//arr={Sam,went,went,to,to ,to ,his ,busine…


This content originally appeared on DEV Community and was authored by NJ


import java.util.*;
import java.lang.*;
class Demo{
    public static void main(String[] args){
        String sen = "Sam went went to to to his business";
        String[] arr = sen.split(" ");
        //arr={Sam,went,went,to,to ,to ,his ,business};
        Set<String> s = new LinkedHashSet<String>();
        for(int i=0;i<arr.length;i++){
            s.add(arr[i]);
        }
        for(String ss:s){
            System.out.print(ss+" ");
        }
        System.out.println();
    }   

}

Image description


This content originally appeared on DEV Community and was authored by NJ


Print Share Comment Cite Upload Translate Updates
APA

NJ | Sciencx (2023-04-27T03:00:58+00:00) remove duplicate words from string in java. Retrieved from https://www.scien.cx/2023/04/27/remove-duplicate-words-from-string-in-java/

MLA
" » remove duplicate words from string in java." NJ | Sciencx - Thursday April 27, 2023, https://www.scien.cx/2023/04/27/remove-duplicate-words-from-string-in-java/
HARVARD
NJ | Sciencx Thursday April 27, 2023 » remove duplicate words from string in java., viewed ,<https://www.scien.cx/2023/04/27/remove-duplicate-words-from-string-in-java/>
VANCOUVER
NJ | Sciencx - » remove duplicate words from string in java. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/04/27/remove-duplicate-words-from-string-in-java/
CHICAGO
" » remove duplicate words from string in java." NJ | Sciencx - Accessed . https://www.scien.cx/2023/04/27/remove-duplicate-words-from-string-in-java/
IEEE
" » remove duplicate words from string in java." NJ | Sciencx [Online]. Available: https://www.scien.cx/2023/04/27/remove-duplicate-words-from-string-in-java/. [Accessed: ]
rf:citation
» remove duplicate words from string in java | NJ | Sciencx | https://www.scien.cx/2023/04/27/remove-duplicate-words-from-string-in-java/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.