46-数组合并和判断集合是否为空的代码以及源代码
2017-03-22 23:26
429 查看
package com.xukaiqiang.ArrayList; import java.util.ArrayList; import java.util.List; import org.apache.commons.lang3.ArrayUtils; import org.springframework.util.CollectionUtils; /** * 数组的合并,集合判断是否为空 */ public class App { public static void main(String[] args) { int[] first = { 0, 1, 2, 3 }; int[] second =null; int[] both = ArrayUtils.addAll(first, second); for (int i : both) { System.out.println(i); } List<String> list=new ArrayList<String>(); System.out.println(CollectionUtils.isEmpty(list)); } }
public static int[] addAll(final int[] array1, final int... array2) { if (array1 == null) { return clone(array2); } else if (array2 == null) { return clone(array1); } final int[] joinedArray = new int[array1.length + array2.length]; System.arraycopy(array1, 0, joinedArray, 0, array1.length); System.arraycopy(array2, 0, joinedArray, array1.length, array2.length); return joinedArray; }
public static boolean isEmpty(Collection<?> collection) { return (collection == null || collection.isEmpty()); }
public boolean isEmpty() {
return size == 0;
}
PS:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
}
相关文章推荐
- @V@ java代码笔记2010-06-12:java控制台输入各类型类实现;以及判断输入字符串里面是否有数字的两种方法:方法1:转换成字符数组;方法2:正则表达式。
- java 判断对象是否为空或者传入集合对象的是否为空,以及判断数组的长度
- 不良代码展示-不要用数组循环判断等于的方式,来判断一个对象是否在一个集合内
- 纯js集成fck 以及 判断fck内容是否为空的js代码
- C#对多个集合和数组的操作(合并,去重,判断)
- C#数组 多个集合和数组的操作(合并,去重,拆分,判断)
- C#对多个集合和数组的操作(合并,去重,判断)
- php判断是否为数组程序代码
- Arrays - 判断两个数组是否一致 以及常用的判断
- C#对多个集合和数组的操作(合并,去重,判断)
- jQuery判断checkbox(复选框)是否被选中以及全选、反选实现代码
- C#对多个集合和数组的操作(合并,去重,判断)
- js实现数组去重、判断数组以及对象中的内容是否相同
- 判断一个数组是否已经排好序以及二分查找
- 用递归判断一个数组是否递增 JAVA代码
- JS判断元素是否在数组内的实现代码
- 获取集合、数组后要判断为空的必要性以及根据构造器创建对象后不是null的证实
- java判断循环数组是否连续并获取不连续的项以及重复项
- webex js 判断是否是ie 以及兼容性代码
- C# 对多个集合和数组的操作(合并、去重复、判断)