当前位置:网站首页>Collection tool class
Collection tool class
2022-08-10 05:50:00 【hagong9】
package com.zhang.collection_;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.Iterator;public class Collections_ {public static void main(String[] args) {ArrayList list = new ArrayList();list.add("jack");list.add("blank");list.add("ann");list.add("lucy");list.add("KK");System.out.println("Original collection"+list);//swap(List, int, int) swaps the two int position elements in the listCollections.swap(list,0,3);System.out.println("After swap"+list);//sort(list) Sorts the specified List in ascending order according to the natural order of the elements (by string size)Collections.sort(list);System.out.println("After natural sorting"+list);//sort(list.Comparator): Sort the List collection according to the specified Comparator generation orderCollections.sort(list, new Comparator() {@Overridepublic int compare(Object o1, Object o2) {return ((String)o1).length() - ((String)o2).length();}});System.out.println("After sorting by length" + list);//reverse() reverse the elementCollections.reverse(list);System.out.println("After reversing the order"+list);//shuffle() shuffles the elementsCollections.shuffle(list);System.out.println("After scrambled"+list);//Object max(Collections) Returns the largest element in the collection according to the natural ordering of the elements.System.out.println("Maximum element in natural order" + Collections.max(list));//Object max(Collections Comparator): According to the order of Comparator, return the largest element in the collectionSystem.out.println("Return the element with the largest length"+Collections.max(list, new Comparator() {@Overridepublic int compare(Object o1, Object o2) {return ((String)o1).length() - ((String)o2).length();}}));//Object min(Collections) According to the natural sorting of elements, return the smallest element in the collection//Object max(Collections Comparator): According to the order of Comparator, return the smallest element in the collection//Same as above o1 o2 position swap//int frequency(Collections,Object) Returns the number of occurrences of the specified elementSystem.out.println("Number of occurrences of KK"+ Collections.frequency(list,"KK"));//void copy(List dest, list list) copies the contents of the list to dest//If the original set src size is larger than the subsequent dest, an exception will be thrownArrayList dest = new ArrayList();//In order to complete the copy, we must first assign a value to dest, the size is the same as the size of srcfor (int i = 0; i 原网站版权声明
本文为[hagong9]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/222/202208100529210482.html
边栏推荐
- redis集群模式
- wiki confluence 安装
- 链读精选:星巴克着眼于数字收藏品并更好地吸引客户
- Linux数据库Oracle客户端安装,用于shell脚本用sqlplus连接数据库
- Chained Picks: Starbucks looks at digital collectibles and better engages customers
- 链读|最新最全的数字藏品发售日历-07.29
- cesium listens to map zoom or zoom to control whether the content added on the map is displayed
- IO流【】【】【】
- ResNet的基础:残差块的原理
- transaction, storage engine
猜你喜欢
String常用方法
The latest and most complete digital collection sales calendar-07.26
Analysis of the investment value of domestic digital collections
定时器(setInterval)的开启与关闭
链读精选:星巴克着眼于数字收藏品并更好地吸引客户
The complex "metaverse" will be interpreted for you, and the Link Reading APP will be launched soon!
链读 | 最新最全的数字藏品发售日历-07.28
泛型笔记()()()
最新最全的数字藏品发售日历-07.27
【List练习】遍历集合并且按照价格从低到高排序,
随机推荐
Models corresponding to each architecture instruction set
Mini Program Study Notes: Communication between Mini Program Components
el-cascader级联选择器的子菜单双击两次才显示被选中的内容
集合 Map
关于cfar检测的学习及仿真
文本元素
win12 修改dns脚本
error in ./node_modules/cesium/Source/ThirdParty/zip.js
来亲自手搭一个ResNet18网络
数据库 笔记 创建数据库、表 备份
sqlplus displays the previous command and the available backspace key
Timer (setInterval) on and off
去中心化和p2p网络以及中心化为核心的传统通信
链读推荐:从瓷砖到生成式 NFT
latex图片排版技巧总结
笔记1
Module build failed TypeError this.getOptions is not a function报错解决方案
IO stream【】【】【】
网络安全5
Knowledge Distillation Thesis Learning