当前位置:网站首页>Arrays and collections
Arrays and collections
2022-07-06 05:52:00 【Python's path to immortality】
Length() Used to find String The length of the string object ,length Is to seek String Length of array
Array declaration and initialization
String[] a= new int[3] The length of the array is fixed and cannot be modified
String [] a=new String[]{“a”,”b”,”c”} The value of the first element in is a instead of “a”;
Array traversal method :
1for(var i:a ){
system.out.println(i);
}
2For(int i=0;i<a.lenth;i++){
System.out .prontln(i);}
3Arrays.stream(a).foreach(system.out::println)
Assign random numbers to the elements in the array
Random rand=new Random();
Int[] s=new int[10];
S[i]=rand.nextInt(100)+1;
Sort using Arrays.sort The method needs to int[] Convert to Integer object
Descending Arrays.sort(n,(a,b)->b-a)
Arrays.sort(ss, Comparator.reverseOrder())
// Bubbling
for (int i = 0; i < nums.length - 1; i++) {
for (int j = 0; j < nums.length - 1 - i; j++) { //> Ascending < Descending
if (nums[j] < nums[j + 1]) {
int t = nums[j]; nums[j] = nums[j + 1];
nums[j + 1] = t; }
Arrays.fill( Array name , Location )// Fill the array
Sorts// Ascending order
Arrays.binarySearch(n, 150)) Sort before you can find
aggregate Collection
ArrayList yes list Implementation class of
List.of Added list Fixed size list
List.add() Additive elements
List.remove Remove elements ( The element that first appears from the left )
List.clear() Empty the set
List.contains Determine whether there is
// Instantiation ArrayList Use generics var list = new ArrayList(); Traversal is the same as array
//array list transformation
int[] arr = new int[]{1,2,3};
List lis = new ArrayList(Arrays.asList(arr));
System.out.println(lis.get(0)); // take arr Put the whole as a parameter list in
System.out.println(lis.size())
aggregate Arraylist And Array Array type conversion (
// Array to set () To put it bluntly, it is to add an array as a set element )
Integer[] nums = new Integer[] { 10, 20, 30, 40, 50 };
List list = Arrays.asList(nums);
// Set array (list.toArray)
//Arrays.toString Output the array as a string

List Generic sort
List list = new ArrayList<>();
List.sort// Ascending
Collcetions.shuffle(list)// Disorder
Collcetions.sort(list)// Disorder
Collections.sort(ls, Comparator.reverseOrder());// Descending
list.sort((a, b) -> b.getScore() - a.getScore());// According to the ascending order of grades

list.sort(Comparator.comparingInt(User::name));// Sort by name ava.util.Comparator Interface It can realize multi-level sorting
![]()
Add two data at the same time
List.add(S)
Set Set :
HashSet :Set The implementation of the interface has good access and search performance At the bottom is the hash table
disorder , Out of sync , The set value can be empty and cannot contain duplicate elements
Traverse set.foreach(system.out::println)
边栏推荐
- 网络协议模型
- [email protected] raspberry pie
- The difference and usage between continue and break
- HCIA复习
- B站刘二大人-Softmx分类器及MNIST实现-Lecture 9
- B站刘二大人-线性回归及梯度下降
- What is independent IP and how about independent IP host?
- ArcGIS application foundation 4 thematic map making
- (column 22) typical column questions of C language: delete the specified letters in the string.
- How to use PHP string query function
猜你喜欢

Web服务连接器:Servlet

Processes and threads
![[Baiwen smart home] first day of the course_ Learn Embedded and understand the development mode of bare metal and RTOS](/img/ed/8d112054f31bd7e593050d1278b9f1.jpg)
[Baiwen smart home] first day of the course_ Learn Embedded and understand the development mode of bare metal and RTOS

A master in the field of software architecture -- Reading Notes of the beauty of Architecture

Hongliao Technology: Liu qiangdong's "heavy hand"

Memory and stack related concepts

PDK工藝庫安裝-CSMC

B站刘二大人-线性回归 Pytorch

ARTS Week 25

Raised a kitten
随机推荐
28io stream, byte output stream writes multiple bytes
通讯录管理系统链表实现
Jushan database appears again in the gold fair to jointly build a new era of digital economy
LTE CSFB process
【SQL server速成之路】——身份验证及建立和管理用户账户
Selective parameters in MATLAB functions
Web service connector: Servlet
Station B Liu Erden - linear regression and gradient descent
C language bubble sort
Leetcode 701 insertion operation in binary search tree -- recursive method and iterative method
Analysis of grammar elements in turtle Library
[experience] install Visio on win11
Web Security (V) what is a session? Why do I need a session?
Cannot build artifact 'test Web: War expanded' because it is included into a circular depend solution
网站进行服务器迁移前应做好哪些准备?
Mysql database master-slave cluster construction
27io stream, byte output stream, OutputStream writes data to file
如何在业务代码中使用 ThinkPHP5.1 封装的容器内反射方法
查詢生產訂單中某個(些)工作中心對應的標准文本碼
How can large websites choose better virtual machine service providers?