当前位置:网站首页>Collections tool class (V)
Collections tool class (V)
2022-06-30 06:19:00 【Java shaping】
Catalog
collections: operation Collection、Map Tool class of
Interview questions :Collection and coLLections The difference between ?
collections: operation Collection、Map Tool class of
The sorting operation :( Are all static Method ) >reverse(List): reverse List The order of the elements in >shuffle(List): Yes List Set elements in random order sort(List): Specify according to the natural order of the elements IList The set elements are sorted in ascending order sort(List, Comparator): According to the designation Comparator The order of production is to List Set elements to sort swap(List,int, int): Will specify list In the collection i The elements and j Exchange elements at Ⅰ lookup 、 Replace Object max(Collection): According to the natural order of the elements , Returns the largest element in a given set Object max(Collection,Comparator): according to Comparator The order of designation , Returns the largest element in a given set Object min(Collection) Object min(Collection,Comparator) int frequency(Collectionl,Object): Returns the number of occurrences of a specified element in a specified collection void copy(List dest,List src): take src Copy the contents of to dest in boolean replaceAll(List list,Object oldVal,Object newVal): Replace with a new value List All old values of the object
copy Code presentation for
@Test
public void test1() {
// void copy(List dest,List src): take src Copy the contents of to dest in
ArrayList arrayList = new ArrayList();
arrayList.add(123);
arrayList.add(354);
arrayList.add(76);
arrayList.add(5);
arrayList.add(-9);
// The abnormal :java.lang.IndexOutOfBoundsException: Source does not fit in dest
// ArrayList arrayList1 = new ArrayList();
// Collections.copy(arrayList1,arrayList);
// Correct :
List arrayList1 = Arrays.asList(new Object[arrayList.size()]);
System.out.println(arrayList1.size());// Is equal to arrayList Of size
Collections.copy(arrayList1, arrayList);
System.out.println(arrayList1);
// CoLlections Class provides multiple synchronizedXxx() Method , This method can wrap the specified collection into a thread synchronized collection ,
// So it can solve the problem of thread safety when multithreading concurrent access to the collection
List list = Collections.synchronizedList(arrayList);
// list It's thread safe
}
}Interview questions :Collection and coLLections The difference between ?
边栏推荐
- Learn fpga---ram IP core and key parameters from the bottom structure
- ES6数组遍历与ES5数组遍历
- Common NPM install errors
- Cisco vxlan configuration
- General contents of learning reinforcement learning
- MySQL數據庫用戶管理
- Image processing 7- image enhancement
- C language final experiment report (student achievement management system) source code
- Base64 explanation: playing with pictures Base64 encoding
- Who doesn't want a blog site of their own - build a blog site WordPress
猜你喜欢

Centos8 install redis
A complete performance test process

Detailed description of methods in the interface

Beauty of Refactoring: when multithreaded batch processing task lifts the beam - Universal scaffold
![[OSPF] comparison between rip and OSPF](/img/72/00e3a05bc5de0e5a66b4675d030911.jpg)
[OSPF] comparison between rip and OSPF

Unable to access the Internet at win10 /11 hotspot

从零开发 stylelint规则(插件)

RSA and AES

MySQL數據庫用戶管理

To: k210 realizes face recognition (code interpretation attached)
随机推荐
Completabilefuture: from understanding to mastering, here are all you want to know
uniapp 微信小程序返回上一页并刷新
HCIA day 1
Installing googleplay environment on Huawei mobile phones
ES6 deconstruction assignment
Feisheng: Based on the Chinese word breaker ik-2 ways to build custom hot word separators Showcase & pit arrangement Showtime
Title: enter two positive integers m and N to find their maximum common divisor and minimum common multiple
Using C language pure for loop to implement ilovey
As function memo
[OSPF] comparison between rip and OSPF
SparseArray
Simple example of class template
Suggestion: use tools:overrideLibrary
C language final experiment report (student achievement management system) source code
Multithreading advanced level
Is it safe to open an account online? Can you open an account to speculate on the Internet?
[wechat applet: single or multiple styles, background color, rounded corners]
Mysql database learning notes - foreign keys, table connections, subqueries, and indexes for MySQL multi table queries
图像处理7-图像增强
Rhcsa day 3