当前位置:网站首页>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)
边栏推荐
- Wib3.0 leapfrogging, in leapfrogging (ง • ̀_•́) ง
- Yunxiaoduo software internal test distribution test platform description document
- [SQL Server fast track] - authentication and establishment and management of user accounts
- PDK工艺库安装-CSMC
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- [experience] when ultralso makes a startup disk, there is an error: the disk / image capacity is too small
- J'ai un chaton.
- Yygh-11-timing statistics
- [JVM] [Chapter 17] [garbage collector]
- 数字经济破浪而来 ,LTD是权益独立的Web3.0网站?
猜你喜欢

关于 PHP 启动 MongoDb 找不到指定模块问题

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

什么是独立IP,独立IP主机怎么样?

How can large websites choose better virtual machine service providers?
![[Jiudu OJ 08] simple search x](/img/a7/12a00c5d1db2deb064ff5f2e83dc58.jpg)
[Jiudu OJ 08] simple search x

Leetcode 701 insertion operation in binary search tree -- recursive method and iterative method

CoDeSys note 2: set coil and reset coil

The difference and usage between continue and break

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

(column 22) typical column questions of C language: delete the specified letters in the string.
随机推荐
Hongliao Technology: how to quickly improve Tiktok store
Is it difficult for an information system project manager?
Closure, decorator
[C language syntax] the difference between typedef struct and struct
[Tang Laoshi] C -- encapsulation: classes and objects
Go language -- language constants
MIT6.s081-2020 Lab2 System Calls
OSPF configuration command of Huawei equipment
Problems encountered in installing mysql8 on MAC
B站刘二大人-数据集及数据加载 Lecture 8
Pytorch代码注意的细节,容易敲错的地方
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Redistemplate common collection instructions opsforvalue (II)
清除浮动的方式
ArcGIS application foundation 4 thematic map making
PDK工藝庫安裝-CSMC
[email protected] raspberry pie
Database: ODBC remote access SQL Server2008 in oracel
Selective parameters in MATLAB functions
C language bubble sort