当前位置:网站首页>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
边栏推荐
猜你喜欢
ORACLE system table space SYSTEM is full and cannot expand table space problem solving process
文章复现:SRCNN
常用类 String概述
Chain Reading Recommendation: From Tiles to Generative NFTs
Ten years of sharpening a sword!The digital collection market software, Link Reading APP is officially open for internal testing!
MySql 约束
ResNet的基础:残差块的原理
The latest and most complete digital collection sales calendar-07.27
.las转.txt 再转.pcd,编译运行中出现的错误
transaction, storage engine
随机推荐
智能合约和去中心化应用DAPP
转载fstream,ifstream的详细用法
The submenu of the el-cascader cascade selector is double-clicked to display the selected content
cesium rotate image
第二次实验
文章复现:超分辨率网络FSRCNN
Chain Reading|The latest and most complete digital collection sales calendar-07.29
Bifrost 同步数据库实现微服务跨库数据同步
PCL点云配准--ICP or keypoints+features
Smart contracts and DAPP decentralized applications
Mockito基本使用指南
wiki confluence installation
网络安全作业
Small program wx.request simple Promise package
Canal reports Could not find first log file name in binary log index file
I use this recruit let the team to improve the development efficiency of 100%!
训练集Loss收敛,但是测试集Loss震荡的厉害?
MySql 约束
Privatisation build personal network backup NextCloud
操作表 函数的使用