当前位置: 首页 > news >正文

Java -- Arrays类-- System类-- BigInteger和BigDecimal类

1. Arrays类

1. toString 返回数组的字符串形式   Arrays.toString(arr)

2. sort排序(自然排序和定制排序) Integer arr【】={1,-1,7,0};

3. binarySearch 通过二分搜索法进行查找,要求必须排好序

    int index = Arrays.binarySearch(arr,3);

4. 代码展示

 Integer[] arr = {1, 2, 90, 151};// binarySearch 通过二分搜索法进行查找,要求必须排好// 使用这个方法 binarySearch 二叉查找// 要求该数组 是有序的   如果该数组是无序的 不能使用binarySearch// 如果数组不存在该元素 返回-1;int index = Arrays.binarySearch(arr, 1);System.out.println("index= " + index);//copyOf 数组元素的赋值// 从arr数组中,拷贝 arr.length个元素到newArr数组中//Integer[] newArr = Arrays.copyOf(arr,arr.length);System.out.println("==拷贝执行完毕后==");System.out.println(Arrays.toString(newArr));// ill数组元素的填充Integer[] num = new Integer[]{9,3,2};Arrays.fill(num,99);// 使用99去填充 num数组 理解成替换原来的元素System.out.println("==num数组填充后==");System.out.println(Arrays.toString(num));//equals 比较俩个数组元素内容是否完全一致//ar2r与arr 数组的元素一样//如果不是完全一样 返回falseInteger[] ar2r = {1, 2, 90, 151};boolean equals = Arrays.equals(arr,ar2r);System.out.println("equals="+equals);//asList 将一组值,转换成list// asList 方法 会将(2,3,4,5,6,1)数据转成一个List集合// asList 运行类型List<Integer> asList = Arrays.asList(2,3,4,5,6,1);System.out.println("asList="+asList);System.out.println("asList的运行类型");

2. System类:

1. exit退出当前程序

2. arraycopy:复制数组元素,比较适合底层调用,一般使用Arrays.copyOf完成复制数组。

    int【】 src={1,2,3};

    int【】 dest = new  int[3]

    System.arraycopy(src,0,dest,0,3);

3. currentTimeMillens :返回当前时间距离 1970-1-1 的毫秒数

4. gc:运行垃圾回收机制System.gc();


3. BigInteger和BigDecimal类

介绍 :BigInteger适合保存比较大的整型   BigDecimal适合保存精度更高的浮点数(小数)

add 加  

subtract 减

multiply 乘

divide 除

BigInteger bigInteger = new BigInteger("1231544684844");BigInteger bigInteger2 = new BigInteger("100");System.out.println(bigInteger);// 在对BigInteger进行加减乘除 需要使用对应方法 不能直接使用 + -// 使用相应的方法// 创建一个 要操作的 BigInteger 进行操作BigInteger add = bigInteger.add(bigInteger2);System.out.println(add);//增BigInteger subtract = bigInteger.subtract(bigInteger2);System.out.println(subtract);//减BigInteger multiply = bigInteger.multiply(bigInteger2);System.out.println(multiply);//乘BigInteger divide = bigInteger.divide(bigInteger2);System.out.println(divide);//除
BigDecimal bigDecimal = new BigDecimal("1999.1111111117777777777788888");BigDecimal bigDecimal2 = new BigDecimal("1.1");System.out.println(bigDecimal);// 如果对BigDecimal进行运算 需要使用对应的方法// 创建一个需要操作的BigDecimal 然后调用相应的方法System.out.println(bigDecimal.add(bigDecimal2));System.out.println(bigDecimal.subtract(bigDecimal2));System.out.println(bigDecimal.divide(bigDecimal2));//会有异常 除不尽的情况 可以指定精度;来规避System.out.println(bigDecimal.divide(bigDecimal2, BigDecimal.ROUND_CEILING));//会有异常 除不尽的情况 可以指定精度;来规避

http://www.dtcms.com/a/319100.html

相关文章:

  • 串口通信02 温度传感DS18B20 01 day49
  • jetson上使用opencv的gstreamer进行MIPI和USB摄像头的连接以及udp推流
  • JAVA,Maven分模块设计
  • 语言模型(LM):n-gram模型原理与困惑度(Perplexity)计算详解
  • B-树与B+树
  • AI大模型专题:LLM大模型(初识)
  • dubbo的metadata-report是做啥的
  • 17.11 单卡24G显存微调GLM-4实战:QLoRA到全参数调优,准确率狂飙42.7%
  • Qt: WA_DontCreateNativeAncestors
  • 【缩点 拓扑序】P3119 [USACO15JAN] Grass Cownoisseur G|省选-
  • 【关于Java中==和equals( )和hashCode( )三者异同】
  • 写Rust GPU内核驱动:GPU驱动工作原理简述
  • 【性能测试】---测试工具篇
  • 医疗人效管理新标杆:盖雅工场如何赋能健康服务企业提质增效
  • 「iOS」————自动释放池底层原理
  • CSS包含块与百分比取值机制完全指南
  • 数据分析——Pandas库
  • 添加内容溢出时显示完整内容提示的功能
  • QT5.15 mingw
  • c++之 栈浅析
  • Python 数据类型及数据类型转换
  • platform总线简介和使用场景说明
  • 基于Ruby的IP池系统构建分布式爬虫架构
  • 《算法导论》第 9 章 - 中位数和顺序统计量
  • 网页图片视频一键下载+视频去重修改 ,覆盖B站等多个平台
  • 【基础知识】springboot+vue 基础框架搭建(更新中)
  • 中国MCP市场:腾讯、阿里、百度的本土化实践
  • AI绘画:生成唐初李世民全身像提示词
  • 前后端加密传数据实现方案
  • 强反光干扰下读数误差↓79%!陌讯多模态算法在仪表盘识别场景的落地优化​