当前位置:网站首页>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 ?
边栏推荐
- 880. 索引处的解码字符串
- [deep learning] data segmentation
- Record a problem tracking of excessive load
- Zibll sub theme v6.4.1wordpress open source download_ Crack the original / use it directly / no tutorial required
- InputStream to inputstreamsource
- Learn fpga---ram IP core and key parameters from the bottom structure
- Docker is equipped with the latest MySQL image
- Wechat applet mall project
- Uniapp wechat applet returns to the previous page and refreshes
- 谁不想要一个自己的博客网站呢 - 搭建博客网站wordpress
猜你喜欢

Rhcsa day 3
![[ansible series] fundamentals -01](/img/b4/1f3284338c75acb5259849a45bbfbe.jpg)
[ansible series] fundamentals -01

Configure the user to log in to the device through telnet -- AAA local authentication

MySQL log management, data backup and recovery

MySQL 索引

STM32F103 series controlled OLED IIC 4-pin

Centos8 install redis

Balanced binary tree judgment of Li Kou 110 -- classic problems
![[wechat applet: single or multiple styles, background color, rounded corners]](/img/01/0381915591b0d3c13afbba4d50952d.png)
[wechat applet: single or multiple styles, background color, rounded corners]

Base64 explanation: playing with pictures Base64 encoding
随机推荐
[ansible series] fundamentals -01
Subnet division and subnet summary
General contents of learning reinforcement learning
Balanced binary tree judgment of Li Kou 110 -- classic problems
Potential bottleneck of redis
【微信小程序:单选、多选样式,背景色,圆角】
Record a problem tracking of excessive load
Multithreading advanced level
Dynamic routing job
Unable to access the Internet at win10 /11 hotspot
Decompilation normal decompilation problems. Solve them yourself
Official win 10 image download
Prototype and prototype chain in JS
Basic use of markdown
When to use redis
ES6 array traversal and Es5 array traversal
Suggestion: use tools:overrideLibrary
Spin official tutorial
ES6 extended operator (...)
SparseArray