How to find Frequency Of words in a Given String using Array List.
SOURCE : UsingList.javaimport java.util.Arrays;import java.util.Collections;import java.util.HashSet;import java.util.List;public class UsingList { public static void main(String[] args) { String s = "india is my country and india is only the way out india and and their"; s = s.trim(); List ls = Arrays.asList(s.split(" ")); HashSet hs = new HashSet(ls); for (String word : hs) { System.out.println(word + ":::" + Collections.frequency(ls, word)); } }} INPUTString s = "india is my country and india is only the way out india and and their"OUTPUT
country:::1their:::1is:::2india:::3my:::1way:::1out:::1the:::1and:::3only:::1

0 comments :
Post a Comment