给定一个字符串数组,内容如下:
String[] words = {"no pains, no gains."
"well begun is half done.",
" where there is a will, there is a wa
编写程序,创建一个HashMap对象,它的键是英文单词,值是该单词的个数。
HashMap<String, Integer> wordMap = new HashMap<>();
从字符串数组words中解析出每个单词存放到wordMap中,同时统计单词数量。将HashMap修改为TreeMap,再次运行程序,结果如下:
共有13个不同的单词 {no=2, a=2, half=1, will=1, begun=1, pains=1, is=3, gains=1, done=1, way=1, there=2, well=1, where=1} {a=2, begun=1, done=1, gains=1, half=1, is=3, no=2, pains=1, there=2, way=1, well=1, where=1, will=i}
