Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 27, 2023 03:00 am GMT

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

Image description


Original Link: https://dev.to/realnamehidden1_61/remove-duplicate-words-from-string-in-java-29e0

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To