com.github.linushp.commons.CollectionUtils Maven / Gradle / Ivy
package com.github.linushp.commons;
import com.github.linushp.commons.ifs.CharFilter;
import com.github.linushp.commons.ifs.ObjectFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Array;
import java.util.*;
public class CollectionUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(CollectionUtils.class);
/**
* 对集合中的每一个元素变成字符串后添加前缀和后缀
*
* @param collection 集合
* @param prefix 字符串前缀
* @param suffix 字符串后缀
* @return
*/
public static List eachWrap(Collection collection, String prefix, String suffix) {
List result = new ArrayList<>();
for (Object obj : collection) {
if (obj != null) {
result.add(prefix + obj.toString() + suffix);
}
}
return result;
}
public static List repeatList(T obj, int repeatTimes) {
List result = new ArrayList<>();
for (int i = 0; i < repeatTimes; i++) {
result.add(obj);
}
return result;
}
public static List[] listKeyValues(Map map) {
List