⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wordcounter15.java

📁 JAVA编程思想第四版英文原版习题答案. pdf原版的
💻 JAVA
字号:
// containers/WordCounter15.java
// TIJ4 Chapter Containers, Exercise 15, page 847
// Repeat Exercise 13 using a SlowMap. 
import net.mindview.util.*;	
import static net.mindview.util.Print.*;
import java.util.*;

public class WordCounter15 {
	public static void main(String[] args) {
		// File whose words are to be counted:
		String fileName = "WordCounter15.java";
		// List of all words in file:
		ArrayList<String> wordList = new TextFile(fileName, "\\W+");
		SlowMap<String,Integer> wordCount = new SlowMap<String,Integer>();
		Iterator it = wordList.iterator();
		while(it.hasNext()) {
			String s = (String)it.next();
			if(!(wordCount.containsKey(s))) wordCount.put(s,1);
			else {
				int count = wordCount.get(s);
				wordCount.put(s, ++count);
			}
		}
		print(wordCount);		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -