CollectionUtils的使用
创始人
2025-01-11 09:36:47
0

1、非空判断

判断集合是否为空

List对象list,可以使用CollectionUtils中的isEmpty方法来判断list是否为空。代码如下

List list = new ArrayList<>(); boolean isEmpty = CollectionUtils.isEmpty(list); System.out.println(isEmpty); 

2、数组转换为List对象

使用CollectionUtils中的arrayToList方法将该数组转换为List对象

String[] array = {"a", "b", "c"}; List list = CollectionUtils.arrayToList(array); System.out.println(list);

3、枚举对象Enumeration转换成数组

使用CollectionUtils中的toArray方法将enumeration转换成String数组

Enumeration enumeration = new StringTokenizer("shanghai", "hangzhou","shenzhen");  String[] array = (String[]) CollectionUtils.toArray(enumeration, new String[0]);  for (String s : array) {     System.out.println(s); } 

4、数组合并到List对象

CollectionUtils中的mergeArrayIntoCollection方法将数组中的元素合并到List对象中

String[] array = {"shanghai", "shenzhen", "hangzhou"}; List list = new ArrayList<>(); CollectionUtils.mergeArrayIntoCollection(array, list); System.out.println(list);

5、判断集合中是否包含指定元素

使用CollectionUtils中的contains方法来判断List对象中是否包含某个元素

List list = new ArrayList<>(); list.add("shanghai"); list.add("hangzhou"); boolean contains = CollectionUtils.contains(list.iterator(), "hangzhou"); System.out.println(contains);

6、判断集合A中是否包含集合B中的任意一个元素

使用CollectionUtils中的containsAny方法来判断

    List a = new ArrayList<>();     a.add("shanghai");     a.add("hangzhou");     List b = new ArrayList<>();     b.add("shenzhen");     b.add("hangzhou");     boolean isContain = CollectionUtils.containsAny(a, b);     System.out.println(isContain); 

相关内容

热门资讯

围绕透视问题!wepoker透... 围绕透视问题!wepoker透视脚本视频,德普之星怎么开辅助,其实是真的有挂(有挂透视)1、德普之星...
揭露一下!光明辅助器,潮汕掌上... 揭露一下!光明辅助器,潮汕掌上娱破解,总是真的有挂(哔哩哔哩)1、打开软件启动之后找到中间准星的标志...
无独有偶!wepoker私人局... 无独有偶!wepoker私人局透视,智星德州可以透视吗,都是确实有挂(有挂透明挂)1.智星德州可以透...
教你一下!四川家园游戏辅助软件... 教你一下!四川家园游戏辅助软件,阿拉斗牌作弊视频,一贯是真的有挂(哔哩哔哩)四川家园游戏辅助软件能透...
黑科技辅助挂!wepoker怎... 黑科技辅助挂!wepoker怎么看底牌,德扑之星辅助工具如何设置,一贯存在有挂(有挂秘籍)1、很好的...
解迷一下!福州十八扑外卦视频,... 解迷一下!福州十八扑外卦视频,wepoker辅助器免费下载,原来真的是有挂(哔哩哔哩);1、操作简单...
据玩家消息!hhpoker到底... 据玩家消息!hhpoker到底可以作弊吗,德普之星辅助工具如何设置,竟然真的有挂(有挂分享)据玩家消...
关于一下!微信开心泉州辅助器,... 关于一下!微信开心泉州辅助器,赣牌圈的好牌几率,一直存在有挂(哔哩哔哩)1、超多福利:超高返利,海量...
今日!德州局怎么透视,智星菠萝... 今日!德州局怎么透视,智星菠萝可以辅助吗,切实是真的有挂(确实有挂)1、智星菠萝可以辅助吗免费脚本咨...
教你一下!边锋干瞪眼ios辅助... 教你一下!边锋干瞪眼ios辅助,祺友互娱脚本,竟然有挂(哔哩哔哩);1、每一步都需要思考,不同水平的...