Java后台通过Collections获取list集合中最大数,最小数代码
作者:百度没有我的爱 时间:2023-03-15 19:53:05
我就废话不多说了,大家还是直接看代码吧~
package com.jalor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Jalor_20180728 {
public static void main(String[] args) {
List<Integer> rst2 = new ArrayList<>();
rst2.add(1);
rst2.add(2);
rst2.add(3);
rst2.add(8);
rst2.add(0);
Collections.max(rst2);
Collections.min(rst2);
System.out.println("max: "+ Collections.max(rst2));
System.out.println("min: "+ Collections.min(rst2));
}
}
实践是检验真理的唯一标准,结果如下
补充知识:java求list集合的最大值、最小值、总和、总个数、平均数、标准偏差
1、标准偏差公式如下:
2、java求list集合的总组数、和、平均数、总体标准偏差代码如下:
package com.cn;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Test4 {
public static void main(String[] args) {
TotalityStandardDeviation();
}
public static void TotalityStandardDeviation(){
List<String> list = new ArrayList<String>();
list.add("1.24");
list.add("2.24");
list.add("5");
String maxvalue=Collections.max(list);
System.out.println("最大值==="+maxvalue);
String minvalue=Collections.min(list);
System.out.println("最小值==="+minvalue);
int count=0;//总个数
double sum=0;//总和
double average=0;//平均数
double dStdDev=0;//总体标准偏差
//求总组数
count=list.size();
System.out.println("总个数==="+count);
//求和
for(int i = 0; i < list.size(); ++i)
{
sum += Double.parseDouble(list.get(i));
}
//求平均数
average = sum/list.size();
DecimalFormat df = new DecimalFormat(".000");
System.out.println("总和==="+df.format(sum));
System.out.println("平均数==="+df.format(average));
//求总体标准偏差
double dsum=0;
for(int i = 0; i < list.size(); ++i)
{
double s=Double.parseDouble(list.get(i)) - average;
dsum += Math.pow(s,2);
}
dStdDev = Math.sqrt(dsum / list.size());
System.out.println("标准偏差值==="+df.format(dStdDev));
}
}
3、代码计算结果如下
4、方差 标准差-均方差在线计算器结果如下:
来源:https://blog.csdn.net/u013199013/article/details/81256453
标签:Java,Collections,list,最大数,最小数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java 多线程Synchronized和Lock的区别
2023-08-14 11:39:09
Android自定义view实现电影票在线选座功能
2022-04-26 22:26:59
![](https://img.aspxhome.com/file/2023/1/138461_0s.gif)
剖析Java中阻塞队列的实现原理及应用场景
2023-09-01 17:33:07
聊聊Controller中RequestMapping的作用
2021-12-08 20:48:45
![](https://img.aspxhome.com/file/2023/9/63099_0s.png)
c#使用正则表达式匹配字符串验证URL示例
2023-01-01 10:40:10
java秒杀之redis限流操作详解
2022-07-08 09:26:57
Java排序算法总结之希尔排序
2022-07-16 13:19:11
C#中TransactionScope的使用小结
2022-02-15 01:53:08
![](https://img.aspxhome.com/file/2023/5/122625_0s.jpg)
详解Android Gradle插件3.0挖坑日记
2022-02-06 09:03:19
![](https://img.aspxhome.com/file/2023/7/130437_0s.png)
Unity shader实现高斯模糊效果
2023-11-17 20:23:45
![](https://img.aspxhome.com/file/2023/4/102184_0s.jpg)
android 控件同时监听单击和双击实例
2022-11-16 15:45:33
![](https://img.aspxhome.com/file/2023/7/87317_0s.jpg)
Android中显示GIF动画的实现代码
2022-01-26 23:36:50
![](https://img.aspxhome.com/file/2023/8/139178_0s.jpg)
设计模式系列之组合模式及其在JDK和MyBatis源码中的运用详解
2022-12-27 12:56:57
![](https://img.aspxhome.com/file/2023/6/68156_0s.png)
详解基于MVC的数据查询模块进行模糊查询
2022-02-13 19:26:49
Spring Boot基础学习之Mybatis操作中使用Redis做缓存详解
2023-01-19 16:35:55
![](https://img.aspxhome.com/file/2023/1/67961_0s.jpg)
springcloud-gateway整合jwt+jcasbin实现权限控制的详细过程
2023-11-20 12:57:09
![](https://img.aspxhome.com/file/2023/8/59078_0s.png)
Java 添加、读取和删除 Excel 批注的操作代码
2023-10-28 21:55:36
![](https://img.aspxhome.com/file/2023/5/81885_0s.png)
Unity实现俄罗斯方块(三)
2022-02-01 19:07:14
IntelliJ IDEA(或者JetBrains PyCharm)中弹出"IntelliJ IDEA License Activation"的解决办法
2021-12-11 09:39:10
![](https://img.aspxhome.com/file/2023/6/120536_0s.png)
C# FileStream实现大文件复制
2021-06-14 11:00:53
![](https://img.aspxhome.com/file/2023/8/96348_0s.png)