• 22.2


     1 import java.io.File;
     2 import java.io.FileNotFoundException;
     3 import java.util.HashMap;
     4 import java.util.Map;
     5 import java.util.Scanner;
     6 import java.util.Set;
     7 import java.util.*;
     8 
     9 public class S22_2 {
    10 
    11     public static void main(String[] args) {
    12         // TODO Auto-generated method stub
    13         Map<String,Integer> myMap = new TreeMap<String,Integer>();
    14         File myFile = new File("txt.txt");
    15         try {
    16             Scanner input = new Scanner(myFile);
    17             while(input.hasNext()){
    18                 String str = input.next().toLowerCase();
    19                 if(myMap.get(str) == null){
    20                     myMap.put(str, 1);
    21                 } else {
    22                     int value = myMap.get(str).intValue();
    23                     value++;
    24                     myMap.put(str,value);
    25                 }
    26             }
    27         } catch (FileNotFoundException e) {
    28             // TODO Auto-generated catch block
    29             e.printStackTrace();
    30         }
    31         Set<Map.Entry<String, Integer>> entrySet = myMap.entrySet();    
    32         
    33         for(Map.Entry<String, Integer> entry:entrySet)
    34             System.out.println(entry.getKey() + "	" +
    35         entry.getValue());            
    36     }
    37 
    38 }
    View Code
  • 相关阅读:
    XML入门
    BOM编程
    hdfs高可用
    Hadoop搭建问题及解决方案 --持续更新
    hadoop3完全分布式搭建
    hadoop环境搭建笔记
    hadoop3.x介绍
    基于JavaAPI对远程hdfs的操作
    13. Roman to Integer C++
    9. Palindrome Number(回文数)C++
  • 原文地址:https://www.cnblogs.com/wanjiang/p/6052633.html
Copyright © 2020-2023  润新知