当前位置:网站首页>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)
边栏推荐
- Web service connector: Servlet
- 实践分享:如何安全快速地从 Centos迁移到openEuler
- Report on the competition status and investment decision recommendations of Guangxi hospital industry in China from 2022 to 2028
- 网站进行服务器迁移前应做好哪些准备?
- 【SQL server速成之路】——身份驗證及建立和管理用戶賬戶
- [string] palindrome string of codeup
- High quality coding tool clion
- Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
- Installation de la Bibliothèque de processus PDK - csmc
- Node 之 nvm 下载、安装、使用,以及node 、nrm 的相关使用
猜你喜欢

C language learning notes (mind map)
![[experience] install Visio on win11](/img/f5/42bd597340d0aed9bfd13620bb0885.png)
[experience] install Visio on win11

Promise summary

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

What preparations should be made for website server migration?

Report on market depth analysis and future trend prediction of China's arsenic trioxide industry from 2022 to 2028

P2802 回家

PDK工藝庫安裝-CSMC

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

Jushan database appears again in the gold fair to jointly build a new era of digital economy
随机推荐
Zoom through the mouse wheel
【SQL server速成之路】——身份验证及建立和管理用户账户
First knowledge database
Download, install and use NVM of node, and related use of node and NRM
Selective parameters in MATLAB functions
AUTOSAR from getting started to becoming proficient (10) - embedded S19 file analysis
【经验】UltralSO制作启动盘时报错:磁盘/映像容量太小
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
通讯录管理系统链表实现
Raised a kitten
Embedded interview questions (I: process and thread)
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
Query the standard text code corresponding to a work center (s) in the production order
Report on market depth analysis and future trend prediction of China's arsenic trioxide industry from 2022 to 2028
養了只小猫咪
网站进行服务器迁移前应做好哪些准备?
B站刘二大人-数据集及数据加载 Lecture 8
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
Station B Liu Erden softmx classifier and MNIST implementation -structure 9
Auto. JS learning notes 17: basic listening events and UI simple click event operations