您的位置:首页 > 编程语言

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>

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: