当前位置:网站首页>Collections以及Arrays
Collections以及Arrays
2022-06-22 08:00:00 【追梦梓辰】
Collections方法:
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(5);
list.add(4);
//sort排序
System.out.println(list.toString());
Collections.sort(list);
System.out.println(list.toString());
// binarySearch二分查找
int n = Collections.binarySearch(list,5);
System.out.println(n);
// copy复制
List<Integer> list2 = new ArrayList<>();
for (int i=0;i<5;i++){
list2.add(0);
}
//该方法要求目标容量必须大于原目标
Collections.copy(list2,list);
System.out.println(list2.toString());
// reserse反转
Collections.reverse(list);
System.out.println(list.toString());
// shuffle 打乱
Collections.shuffle(list);
System.out.println(list);
//list转成数组
Integer[] arr = list.toArray(new Integer[0]);
System.out.println(arr.length);
//数组转集合
String[] namelist ={
"ls","he"};
//受限集合,不能添加和删除
List<String> list3 = Arrays.asList(namelist);
System.out.println(list3.toString());
}
Arrays方法:
public static void main(String[] args) {
int[] arr = {
1,2,5,6,3};
//数组排序
// Arrays.sort(arr);
// for (int a:arr
// ) {
// System.out.println(a);
// }
//将数组里面的内容全部打印出来
System.out.println(Arrays.toString(arr));
//比较数组元素是否相等
int[] arr1 = {
1,2,5,6,3};
System.out.println(Arrays.equals(arr,arr1));
//binarysearch 二分查找法找指定元素的索引值
System.out.println(Arrays.binarySearch(arr,2));
//截取数组 copeof()
int n[] = Arrays.copyOf(arr,3);
System.out.println(Arrays.toString(n));
}
边栏推荐
- Some problems caused by null data in MySQL
- 【Oracle 数据库】奶妈式教程day15 DDL、DML、索引、视图、序列、死锁这一篇就够了
- [songhongkang MySQL database] [advanced chapter] [07] MySQL storage engine
- Xlua environment configuration
- MySQL delete from and subquery as conditions
- 充电宝的玄机
- Xmind 2022思维导图激活版资源?
- Asynchronous sending and receiving of message passing based concurrent programming (MPI)
- JS to assign values to two objects with the same attributes
- Kubernetes practice
猜你喜欢

MySQL master-slave replication

模电实验——实验一 晶体管共射极单管放大器

Stored procedures and functions of MySQL

【 Oracle database】 Nursery Mother Tutorial day13 date Function

The significance of code coverage testing to programming white and its application
![[Oracle database] mammy tutorial day14 conversion function](/img/ef/c468316750c57212a067abd00a10e9.png)
[Oracle database] mammy tutorial day14 conversion function

Excellent cases of data visualization

Node red sends wechat official account message (template message)

【Oracle 數據庫】奶媽式教程 day13 日期函數

Energy and interference of waves
随机推荐
A glimpse of easy rule
Microsoft Remote Desktop 10.7.6正式版
Kubernetes practice
lr 2022超详细安装教程「最新」
IP address planning
Xlua environment configuration
Query where uiwebview is used in the project
OSI and tcp/ip
Lookup encapsulation of unity monobehavior component
Win openfeign from simple to deep
Template code overview
MySQL view
Canvastotempfilepath of wechat
mysql查询group by 1055 问题完美解决,最简单最便捷的方法
Permission Operation of MySQL
Common array operations in JS
Realization of readable and writable files in library management system with C language bidirectional linked list
Simplicity is the best method of network promotion
Docker install redis
MySQL query group by 1055 is the simplest and most convenient way to solve the problem perfectly