当前位置:网站首页>找ArrayList<ArrayList<Double>>中出现次数最多的ArrayList<Double>
找ArrayList<ArrayList<Double>>中出现次数最多的ArrayList<Double>
2022-07-24 05:20:00 【一枚小可爱c】
public static ArrayList<Double> candidate (ArrayList<ArrayList<Double>> list) // 找出数组中出现次数最多的那个数
{
// map的key存放数组中的数字,value存放该数字出现的次数
HashMap<ArrayList<Double>, Integer> map = new HashMap<ArrayList<Double>, Integer>();
for(int i = 0; i < list.size(); i++)
{
if(map.containsKey(list.get(i)))
{
int formerValue = map.get(list.get(i));
map.put(list.get(i), formerValue + 1); // 该数字出现的次数加1
}
else
{
map.put(list.get(i), 1); // 该数字第一次出现
}
}
Collection<Integer> count = map.values();
// 找出map的value中最大值,也就是数组中出现最多的数字所出现的次数
int maxCount = Collections.max(count);
ArrayList<Double> maxNumber = new ArrayList<>();
for(Map.Entry<ArrayList<Double>, Integer> entry : map.entrySet())
{
//得到value为maxCount的key,也就是数组中出现次数最多的数字
if(entry.getValue() == maxCount)
{
maxNumber = entry.getKey();
}
}
return maxNumber;
}边栏推荐
- 《机器学习》(周志华)第2章 模型选择与评估 笔记 学习心得
- 《统计学习方法(第2版)》李航 第16章 主成分分析 PCA 思维导图笔记 及 课后习题答案(步骤详细)PCA 矩阵奇异值 第十六章
- How to quickly recover data after MySQL misoperation
- Unknown collation: ‘utf8mb4_ 0900_ ai_ Solution of CI '
- [activiti] activiti process engine configuration class
- Creation and generation of SVG format map in Heilongjiang Province
- 达梦数据库_常用初始化参数
- ThreadLocal存储当前登录用户信息
- Flink 并行度的理解(parallel)
- 达梦数据库_LENGTH_IN_CHAR和CHARSET的影响情况
猜你喜欢

The female colleague of the company asked me to go to her residence to repair the computer at 11 o'clock at night. It turned out that disk C was popular. Look at my move to fix the female colleague's

达梦数据库_逻辑架构基础

《统计学习方法(第2版)》李航 第十三章 无监督学习概论 思维导图笔记

《统计学习方法(第2版)》李航 第15章 奇异值分解 SVD 思维导图笔记 及 课后习题答案(步骤详细)SVD 矩阵奇异值 十五章

【mycat】mycat相关概念

Connect CRM system and effect advertising, help enterprises with precision marketing, and help enterprises with precision marketing

Multi merchant mall system function disassembly lecture 13 - platform side member management

Similarities and differences of ODS, data mart and data warehouse

《机器学习》(周志华) 第3章 线性模型 学习心得 笔记

Flink Task、Sub-Task、task slot和parallelism
随机推荐
【activiti】activiti环境配置
数据库连接数过大
达梦数据库_支持的表类型,用法,特性
Similarities and differences of ODS, data mart and data warehouse
国内外知名源码商城系统盘点
Unknown collation: ‘utf8mb4_ 0900_ ai_ Solution of CI '
Use streaming media to transfer RSTP to the Web terminal for playback (II) [review]
Mysqldump export Chinese garbled code
The female colleague of the company asked me to go to her residence to repair the computer at 11 o'clock at night. It turned out that disk C was popular. Look at my move to fix the female colleague's
Flink state使用
Zotero快速上手指南
达梦数据库_常用初始化参数
Erp+rpa opens up the enterprise information island, and the enterprise benefits are doubled
Too many database connections
Problems in SSM project configuration, various dependencies, etc. (for personal use)
Wechat applet returns parameters or trigger events
MySQL batch insert demo
Syntax differences between MySQL and Oracle
spark 广播变量和累加器使用和原理
[activiti] activiti process engine configuration class