2个回答
推荐于2017-09-21
展开全部
import java.util.*;
import java.util.regex.*;
public class Yugi{
public static void main(String[] args){
String words = "Look buddy, U got work hard and put yourself in your java, Once you learned the heart of the java, I can guarantee that you win.";
String reg = "[a-zA-Z]+";
Pattern p = Pattern.compile(reg);
Matcher m = p.matcher(words);
HashMap<String, Integer> map = new HashMap<String, Integer>();
int count = 0;
while(m.find()){
count++;
String w = m.group();
if(null == map.get(w)){
map.put(w, 1);
}else{
int x = map.get(w);
map.put(w, x + 1);
}
}
System.out.println(count);
System.out.println(map);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询