Finding repeated words on a string and counting the repetitions

后端 未结 29 890
梦谈多话
梦谈多话 2021-02-05 17:49

I need to find repeated words on a string, and then count how many times they were repeated. So basically, if the input string is this:

String s = \"House, House         


        
29条回答
  •  孤街浪徒
    2021-02-05 18:24

    /*count no of Word in String using TreeMap we can use HashMap also but word will not display in sorted order */
    
    import java.util.*;
    
    public class Genric3
    {
        public static void main(String[] args) 
        {
            Map unique = new TreeMap();
            String string1="Ram:Ram: Dog: Dog: Dog: Dog:leela:leela:house:house:shayam";
            String string2[]=string1.split(":");
    
            for (int i=0; i

提交回复
热议问题