DEV Community

realNameHidden
realNameHidden

Posted on

1 1 1 1 1

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 ,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();
    }   

}


Enter fullscreen mode Exit fullscreen mode

Image description

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay