当前位置:网站首页>Collections and arrays
Collections and arrays
2022-06-22 08:03:00 【Chasing dream Zichen】
Collections Method :
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(5);
list.add(4);
//sort Sort
System.out.println(list.toString());
Collections.sort(list);
System.out.println(list.toString());
// binarySearch Two points search
int n = Collections.binarySearch(list,5);
System.out.println(n);
// copy Copy
List<Integer> list2 = new ArrayList<>();
for (int i=0;i<5;i++){
list2.add(0);
}
// This method requires that the target capacity must be greater than the original target
Collections.copy(list2,list);
System.out.println(list2.toString());
// reserse reverse
Collections.reverse(list);
System.out.println(list.toString());
// shuffle Upset
Collections.shuffle(list);
System.out.println(list);
//list Turn it into an array
Integer[] arr = list.toArray(new Integer[0]);
System.out.println(arr.length);
// Array to set
String[] namelist ={
"ls","he"};
// Restricted set , You can't add or delete
List<String> list3 = Arrays.asList(namelist);
System.out.println(list3.toString());
}
Arrays Method :
public static void main(String[] args) {
int[] arr = {
1,2,5,6,3};
// Array sorting
// Arrays.sort(arr);
// for (int a:arr
// ) {
// System.out.println(a);
// }
// Print out all the contents of the array
System.out.println(Arrays.toString(arr));
// Compare array elements for equality
int[] arr1 = {
1,2,5,6,3};
System.out.println(Arrays.equals(arr,arr1));
//binarysearch The binary search method finds the index value of the specified element
System.out.println(Arrays.binarySearch(arr,2));
// Intercept array copeof()
int n[] = Arrays.copyOf(arr,3);
System.out.println(Arrays.toString(n));
}
边栏推荐
- LNMP environment setup
- (9) Sequential queue and stack queue
- MySQL query database capacity
- Symbolic processing of crash log
- Wx applet vant UI call interface to realize two-level cascade
- Windchill - how to start workflow through API
- Use of keepalived high availability cluster
- MySQL backup - mysqldump
- SQL server changes the primary key index to a non clustered index
- XMIND 2022 mind map active resources?
猜你喜欢

LR 2022 ultra detailed installation tutorial "latest"

(7) Bidirectional linked list

【Oracle 数据库】奶妈式教程 day12 字符函数

Mystery of power bank

Excellent cases of data visualization

Stored procedures and functions of MySQL

Mt4/mql4 getting started to mastering EA tutorial lesson 3 - common functions of MQL language (III) - common functions of K-line value taking

0基础自学stm32(野火)——什么是寄存器?

【宋红康 MySQL数据库 】【高级篇】【06】MySQL的逻辑架构

Microsoft Remote Desktop 10.7.6 official
随机推荐
代码覆盖率测试对编程小白的意义及其使用方法
面试突击59:一个表中可以有多个自增列吗?
Relative positioning, absolute positioning, fixed positioning
AutoCAD 2020.3 Chinese Version (old version)
Asynchronous sending and receiving of message passing based concurrent programming (MPI)
Charles uses
力扣(LeetCode)172. 阶乘后的零(2022.06.21)
Realization of readable and writable files in library management system with C language bidirectional linked list
Runloop detail summary
Concurrent programming summary
模板代码概述
Submit values of various inputs of the form
C#实现语音朗读功能
Kubernetes practice
QT combox的使用示例
Chmod Chmod command
模电实验——实验二 JFET共源极放大电路
Layer drawing method
MySQL query group by 1055 is the simplest and most convenient way to solve the problem perfectly
Collections以及Arrays