An Interest In:
Web News this Week
- April 3, 2024
- April 2, 2024
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
April 27, 2023 03:00 am GMT
Original Link: https://dev.to/realnamehidden1_61/remove-duplicate-words-from-string-in-java-29e0
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(); } }
Original Link: https://dev.to/realnamehidden1_61/remove-duplicate-words-from-string-in-java-29e0
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To