标签:for imp data cti pen ret ati prefix apache
import org.apache.commons.lang.StringUtils; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; /** * @Description list 工具 * @version 1.0.0 **/ public class ArrayUtil { /** * @Description 将数组转换成字符串 * 格式:begin+prefix+str0+suffix+split+prefix+str1+suffix...+end * 为空会跳过 * @param str 被转换的数组 * @param split 分隔符 * @param prefix 前缀 * @param suffix 后缀 * @param begin 开始 * @param end 结束 * @return string */ public static String toString(List<String> str,String split, String prefix, String suffix, String begin, String end){ StringBuffer string = new StringBuffer(); string.append(begin); for(int i = 0;i < str.size();i++){ String s = str.get(i); if(StringUtils.isBlank(s)){ continue; } string.append(prefix); string.append(s); string.append(suffix); if(i < (str.size() - 1)){ string.append(split); } } string.append(end); return string.toString(); } public static String toString(List<String> str, String split, String prefix, String suffix){ return toString(str,split,prefix,suffix,"",""); } public static String toString(List<String> str, String split){ return toString(str,split,"","","",""); } public static String toString(String[] str,String split, String prefix, String suffix, String begin, String end){ List<String> list = Collections.EMPTY_LIST; if(str != null && str.length > 0){ list = Arrays.asList(str); } return toString(list,split,prefix,suffix,begin,end); } public static String toString(String[] str, String split, String prefix, String suffix){ List<String> list = Collections.EMPTY_LIST; if(str != null && str.length > 0){ list = Arrays.asList(str); } return toString(list,split,prefix,suffix); } public static String toString(String[] str, String split){ List<String> list = Collections.EMPTY_LIST; if(str != null && str.length > 0){ list = Arrays.asList(str); } return toString(list,split); } /** * @Description 去除重复 * @param list 集合 * @return List */ public static <T> List<T> removeRepeat(List<T> list){ List<T> result = new ArrayList<>(); for(T data : list){ if(!result.contains(data)){ result.add(data); } } return result; } /** * @Description 数组转in SQL String 例 : ‘1‘,‘2‘ * @param arr 数组 * @return */ public static String arrToStringSql(String arr[]){ StringBuffer stringSql = new StringBuffer(); for(int i = 0; i < arr.length; i++){ if(i == 0){ stringSql.append("‘"); stringSql.append(arr[i]); stringSql.append("‘"); }else { stringSql.append(",‘"); stringSql.append(arr[i]); stringSql.append("‘"); } } return stringSql.toString(); } }
标签:for imp data cti pen ret ati prefix apache
原文地址:https://www.cnblogs.com/SmallStrange/p/10652858.html