一、笔记
使用字符流操作文本文件:FileReader FileWriter 前提:保证程序和文件使用的默认编码表
转换流:OutputStreamWriter InputStreamReader 是FileReader 和 FileWriter的父类
对象流:ObjectOutputStream ObjectInputStream
打印流:PrintStream
WriterStream
二、做题
.现有字符串:"150,510,148,145,321,150,510,148,150,510,148,123,321",
统计每个数字出现的次数,使用集合完成。(提示Map集合)
package com.qfedu.zhuguangyi.test;
import java.util.HashMap;
public class Test2 {
/*
* 3.现有字符串:"150,510,148,145,321,150,510,148,150,510,148,123,321",
统计每个数字出现的次数,使用集合完成。(提示Map集合)
*/
public static void main(String[] args) {
String s="150,510,148,145,321,150,510,148,150,510,148,123,321";
String [] spilt=s.split(",");
HashMap<String, Integer> hm=new HashMap<String,Integer>();
for (int i = 0; i < spilt.length; i++) {
if(hm.containsKey(spilt[i])) {
hm.put(spilt[i], hm.get(spilt[i])+1);
}else {
hm.put(spilt[i], 1);
}
}
System.out.println(hm);
}
}
最巨大的遗憾,是被命运安排!