如何将此大代码转换为Java 8 Lambda表达式

我是java lambda的新手,我正努力以lambda形式制作此代码,请至少有人能告诉我如何用类似this和thx这样的大代码来做。

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class charFile {

public static void main(String args[]) {


    TreeMap<Character, Integer> hashMap = new TreeMap<Character, Integer>();
    File file = new File("new.txt");
    Scanner scanner = null;
    try {
        scanner = new Scanner(file, "utf-8");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    while (scanner.hasNext()) {
        char[] chars = scanner.nextLine().toLowerCase().toCharArray();
        for (Character c : chars) {
            if (!Character.isLetter(c)) {
                continue;
            } else if (hashMap.containsKey(c)) {
                hashMap.put(c, hashMap.get(c) + 1);
            } else {
                hashMap.put(c, 1);
            }
        }
    }
    for (Map.Entry<Character, Integer> entry : hashMap.entrySet()) {
        System.out.println(entry.getKey() + ": " + entry.getValue());
    }


}

}

评论