当前位置:网站首页>Arrays工具类的使用
Arrays工具类的使用
2022-07-30 05:41:00 【想买CT5的小曹】
import java.util.Arrays;
public class Arrays_Study {
public static void main(String[] args) {
int a[] = new int[]{12, 122, 332, 43, 445, 65, 7, 87, 98, 6};
Arrays_Study.printArr(a);
System.out.println("");
Arrays.sort(a);
Arrays_Study.printArr(a);
System.out.println(Arrays.binarySearch(a, 445));
int[] ints = Arrays.copyOf(a, 20);
Arrays_Study.printArr(ints);
Arrays.fill(ints,888);
Arrays_Study.printArr(ints);
boolean equals = Arrays.equals(a, ints);
System.out.println(equals);
int a1[] = new int[]{12, 122, 332, 43, 445, 65, 7, 87, 98, 6};
System.out.println(Arrays.equals(a1, a));
}
public static void printArr(int a[]) {
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
System.out.println("");
}
}
注意点:
1.对于Arrays里面的二分查找一定要先进行排序,然后再进行查找
2.Arrays.equals()比较的是数组里面的值是否相等,比较的不是地址,new出来的对象值要是相等的照样还是true。
public class Arrays_Study {
public static void main(String[] args) {
int a[] = new int[]{12, 122, 332, 43, 445, 65, 7, 87, 98, 6};
int a1[] = new int[]{12, 122, 332, 43, 445, 65, 7, 87, 98, 6};
System.out.println(Arrays.equals(a1, a));
}
}
边栏推荐
- uncategorized SQLException; SQL state [null]; error code [0]; sql injection violation, syntax error
- umi后台项目导航自定义icon问题
- SSTI靶场
- Communication middleware Fast DDS basic concepts and communication examples
- P3 元宝第六单元笔记
- node手写服务器实现访问index页面
- 目前主流浏览器以及对应的内核
- C#利用开源NPlot实现K线图(蜡烛图)
- 连接云服务器Docker中的Mysql 详细图文操作(全)
- 在弹性布局flex布局中,行内标签也能直接加宽高
猜你喜欢
随机推荐
MySQL存储引擎
mysql间隙锁失效?
js 实现自定义签名
C语言人机大战之三字棋博弈
misc-log analysis of CTF
PHP-fpm
记一次流量分析实战——安恒科技(八月ctf)
php-fpm
Misc of CTF - other types of steganography
Koa2框架快速入门与基本使用
【无标题】ES5新特性
CTF之misc-其他类型隐写
DVWA安装教程(懂你的不懂·详细)
umi后台项目导航自定义icon问题
信息安全必备神器之kali
P3 元宝的笔记
FastAPI Quick Start
第一篇博客
盲注、报错注入、宽字节注入、堆叠注入学习笔记
Operators and Interaction Basics