当前位置:网站首页>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 ?
边栏推荐
- 旋转标注工具roLabelImg
- SparseArray
- Configure the user to log in to the device through telnet -- AAA local authentication
- Record a problem tracking of excessive load
- Verilog中case,casez,casex语句的用法
- Picture.....
- Go common judgments
- Detailed description of methods in the interface
- STM32F103 series controlled OLED IIC 4-pin
- Redux source code implementation
猜你喜欢

MySQL数据库用户管理

我做功能测试这么多年的心得

关于Glide加载图片模糊不清楚

Zibll sub theme v6.4.1wordpress open source download_ Crack the original / use it directly / no tutorial required

Develop stylelint rules from zero (plug-ins)

Usage of case, casez and casex statements in Verilog

Learn fpga---ram IP core and key parameters from the bottom structure
![[MD editing required] welcome to the CSDN markdown editor](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[MD editing required] welcome to the CSDN markdown editor

观察者模式、状态模式在实际工作中的使用

RSA and AES
随机推荐
ES6扩展运算符(...)
Application of redis client list in practice
[GPU] basic operation
ES6 arrow function
Title: enter two positive integers m and N to find their maximum common divisor and minimum common multiple
583. 两个字符串的删除操作-动态规划
Prototype and prototype chain in JS
Mysql database user management
ES6 deconstruction assignment
Usage of case, casez and casex statements in Verilog
Traitement d'images 7 - amélioration d'images
反編譯正常回編譯出現問題自己解决辦法
File operation io-part1
PC viewing WiFi password
Picture.....
MySQL transaction
关于Glide加载图片模糊不清楚
MySQL数据库用户管理
880. decoded string at index
A complete performance test process