/**
* String字符串,遍历其中数字,并计算其中的数出现的次数
* @param str
*/
public static void countWords(String str){
//将字符串转换为数组,取掉逗号或者空格
String [] words = str.split(",");
//定义一个map集合,用来存储、计数
Map<String, Integer> map = new HashMap<>();
//遍历数组
for (String word : words) {
//map.containsKey(key) 是判断key在map中key是否存在。
if (map.containsKey(word)){
//如果ke已存在,调用map.get(),获取到他的值加1
map.put(word,map.get(word)+1);
}else {
//否则,就是第一次存入
map.put(word,1);
}
}
//定义一个变量
int num = 0;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
num++;
System.out.print(entry.getKey()+":"+entry.getValue()+"\t");
//当num等于3时,换行
if(num==3){
System.out.println();
//重置num为0
num=0;
}
}
}
public static void main(String[] args) {
//传入字符串
countWords("B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,B7151890053952,39101880590647,39101880590647,B7151890053952,39101880590647,39101880590647,B7151890053952,39101880590647,39101880590647,B7151890053952,39101880590647,39101880590647,B7151890053952,39101880590647,39101880590647,B7151890053952,39101880590647,39101880590647,B7151890053952,39101880590647,39101880590647,B7151890053952,39101880590647,39101880590647,B7151890053952,B7151890053952,39101880590647,39101880590647,39101880612299,39101880590647,39101880590647,39101880612299,39101880590647,39101880612299,39101880590647,39101880612299,39101880590647,39101880590647,39101880612299,39101880590647,39101880590647,39101880612299,39101880590647,39101880612299,39101880612299,39101880612299,39101880612299,39101880590647,39101880612299,39101880590647,39101880590647,39101880590647,39101880590647,39101880612299,39101880590647,39101880590647,39101880590647,39101880590647,39101880612299,39101880590647,39101880590647,39101880590647,39101880612299,39101880612299,39101880590647,39101880590647,39101880590647,39101880612299,39101880590647,39101880590647,39101880590647,39101880590647,39101880612299,39101880590647,39101880590647,39101880590647,39101880590647,39101880612299,39101880590647,39101880590647,39101880590647,39101880590647,39101880612299,39101880590647,39101880590647,39101880590647,39101880590647,39101880612299,39101880590647,39101880590647,39101880590647,39101880590647,39101880612299,39101880590647,39101880590647,39101880590647,39101880590647,39101880612299,39101880590647,39101880613528,39101880613528,39101880613528,39101880613528,39101880621353,39101880621353,39101880621353,39101880621353,39101880621353,39101880621353,39101880621353,39101880621353,39101880621353,39101880621353,39101880621353,39101880621353,39101880621353,39101880621353,39101880621353,39101880621353,39101880621353,39101880621353,39101880621439,B7151890054335,39101880621439,B7151890054335,39101880621439,B7151890054335,39101880621376,39101880621439,B7151890054335,39101880621376,39101880621439,B7151890054335,39101880621439,39101880611460,B7151890054335,39101880621376,39101880621439,39101880611460,B7151890054335,39101880621439,39101880621376,39101880611460,B7151890054335,39101880621376,39101880621439,39101880611460,B7151890054335,39101880621376,39101880621439,39101880611460,39101880621376,39101880621439,B7151890054335,39101880611460,B7151890054335,39101880621439,39101880621376,39101880611460,B7151890054335,39101880621376,39101880621439,39101880611460,B7151890054335,39101880621376,39101880621439,39101880611460,39101880621376,39101880621439,39101880611460,B7151890054335,39101880621376,39101880621439,39101880611460,B7151890054335,B7151890054335,39101880621376,39101880621439,B7151890054335,B7151890054335,39101880621376,39101880621439,B7151890054335,39101880611460,B7151890054335,39101880621439,B7151890054335,39101880611460,B7151890054335,39101880621439,39101880621376,B7151890054335,B7151890054335,39101880611460,39101880621439,B7151890054335,39101880611460,B7151890054335,39101880621376,39101880621439,B7151890054335,39101880611460,B7151890054335,39101880621439,39101880621376,B7151890054335,39101880611460,B7151890054335,39101880621376,B7151890054335,39101880611460,39101880621439,B7151890054335,39101880621376,B7151890054335,39101880611460,39101880621439,B7151890054335,39101880621376,B7151890054335,B7151890054335,39101880621439,39101880621376,B7151890054335,B7151890054335,39101880621439,39101880621376,B7151890054335,B7151890054335,39101880621439,39101880621376,B7151890054335,B7151890054335,39101880621439,39101880621376,B7151890054335,B7151890054335,39101880621376,B7151890054335,B7151890054335,39101880621376,B7151890054335,B7151890054335,39101880621376,39101880613716,B7151890054335,39101880621058,B7151890054598,39101880613720,39101880590256,39101880621058,B7151890054598,39101880621388,39101880621058,B7151890054598,39101880621388,39101880613720,B7151890054598,39101880621388,39101880590102,B7151890054598,39101880590102,B7151890054598,39101880621388,39101880590102,39101880621288,B7151890053768,39101880621388,39101880590102,B7151890054598,39101880621058,39101880621288,39101880621388,B7151890053768,39101880590256,B7151890054598,39101880621288,39101880621058,39101880621388,B7151890053768,39101880590256,39101880590102,B7151890054598,39101880621288,39101880621058,39101880621388,B7151890053768,39101880590256,39101880590102,B7151890054598,39101880621288,39101880621058,39101880621388,B7151890053768,39101880590102,B7151890054598,39101880621288,39101880621058,39101880621388,B7151890053768,39101880590102,B7151890054598,39101880590102,39101880621288,39101880621058,39101880621388,B7151890053768,B7151890054598,39101880590102,39101880621288,39101880621058,39101880621388,B7151890053768,39101880590102,B7151890054598,39101880621288,39101880621058,39101880621117,39101880621388,39101880621117,39101880590102,B7151890054598,39101880621288,39101880621058,39101880621117,39101880621388,39101880590102,B7151890053768,39101880621117,B7151890054598,39101880621288,39101880621058,39101880621117,39101880621388,39101880590102,B7151890053768,39101880621117,B7151890054598,39101880621288,39101880621058,39101880621117,39101880621388,39101880590102,B7151890053768,39101880621117,B7151890054598,39101880621288,39101880621058,39101880621117,39101880621388,39101880590102,B7151890053768,39101880621117,B7151890054598,39101880621058,39101880590102,39101880621288,39101880621117,39101880621388,B7151890053768,39101880621117,B7151890054598,39101880590102,39101880621288,39101880621058,39101880621117,39101880621388,B7151890053768,39101880621117,39101880621388,39101880621058,39101880619262,39101880613689,39101880612317,39101880613605,39101880621288,39101880621058,B7151890054697,39101880619262,39101880621117,39101880612317,39101880621288,39101880613605,39101880621388,39101880621058,B7151890054697,39101880621117,39101880613689,39101880612317,39101880621288,39101880613605,39101880590149,39101880621388,39101880621058,B7151890054697,39101880621117,39101880613689,39101880621288,39101880613605,39101880590149,39101880619262,39101880621058,39101880621388,B7151890054697,39101880621117,39101880613689,39101880621288,39101880613605,39101880612317,39101880590149,39101880619262,39101880621388,39101880621058,B7151890054697,39101880621117,39101880621288,39101880613605,39101880612317,39101880590149,39101880619262,39101880621388,39101880621058,B7151890054697,39101880621117,39101880621288,39101880613605,39101880612317,39101880590149,39101880613689,39101880619262,39101880621388,39101880621058,B7151890054697,39101880621117,39101880621288,39101880613605,39101880590149,39101880613689,39101880619262,39101880621388,39101880621058,B7151890054697,39101880621117,39101880621288,39101880590149,39101880621388,39101880621058,B7151890054697,39101880621117,39101880621288,39101880613605,39101880590149,39101880621388,39101880621058,B7151890054697,39101880621117,39101880621288,39101880613605,39101880619262,39101880621388,39101880621058,B7151890054697,39101880621117,39101880621288,39101880613605,39101880619262,39101880621388,39101880621058,B7151890054697,39101880621437,39101880621117,39101880621288,39101880613605,39101880621437,39101880619262,39101880621388,39101880621058,B7151890054697,39101880621437,39101880621117,39101880621288,39101880621437,39101880619262,39101880621388,39101880621058,B7151890054697,39101880621117,39101880621437,39101880621288,39101880621437,39101880619262,39101880613605,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,39101880590102,B7151890053952,B7151890053952,B7151890053952,39101880590102,B7151890053952,39101880590102,B7151890053952,39101880590102,B7151890053952,39101880590102,B7151890053952,39101880590102,B7151890053952,39101880590102,B7151890053952,39101880590102,B7151890053952,39101880590102,B7151890053952,39101880590102,B7151890053952,39101880590102,B7151890053952,39101880590102,39101880590102,B7151890053952,39101880590102,B7151890053952,39101880590102,B7151890053952,39101880590102,B7151890053952,39101880590102,B7151890053952,39101880590102,B7151890053952,39101880590102,B7151890053952,39101880590102,B7151890053952,39101880590102,B7151890053952,39101880590102,B7151890053952,39101880590102,B7151890053952");
}
String字符串,遍历其中数字,并计算其中的数出现的次数
于 2023-03-16 20:42:16 首次发布