标签:equal end 存在 author rem 长度 sem equals str
1 /** 2 * <p>list操作的工具类</p> 3 */ 4 public class ListUtil { 5 /** 6 * 过滤掉list里面才重复项 7 * 8 * @param list 9 * @return List 10 */ 11 public static List<String> filterRepeat(List<String> list){ 12 int length = list.size(); 13 for(int i = 0;i < length - 1;i++){ 14 String temp = list.get(i).toString(); 15 for(int j = i + 1;j < length;j++){ 16 if(temp.equals(list.get(j))){ 17 list.remove(j); 18 j--; 19 length--; 20 } 21 } 22 } 23 return list; 24 } 25 26 /** 27 * 判断list是否null或者长度为零,常用于从数据库取对象后的判断 28 * 29 * @param list 30 * @return true:空 false:非空 31 */ 32 public static boolean isNull(List list) { 33 if (null == list || list.size() == 0) { 34 return true; 35 } else { 36 return false; 37 } 38 } 39 40 /** 41 * list 是否有存在字符串value的值 42 * 43 * @param list 44 * 链表 45 * @param value 46 * 值 47 * @return true: 存在,false:不存在 48 */ 49 public static boolean valueIsExit(List list, String value) { 50 for (int i = 0; i < list.size(); i++) { 51 if (value.equals(list.get(i).toString())) { 52 return true; 53 } 54 } 55 return false; 56 } 57 58 /** 59 * 将list转化为数组 60 * @param list 61 * @return 62 */ 63 public static String[] toArray(List list) { 64 if (null != list && !list.isEmpty()) { 65 String[] arry = new String[list.size()]; 66 for (int i = 0; i < list.size(); i++) { 67 arry[i] = list.get(i).toString(); 68 } 69 return arry; 70 } 71 return null; 72 73 } 74 75 /** 76 * 77 * 功能说明:将list 转化成字符串 例如 list={1,2,3}转化成1,2,3 78 * 79 * @param list 80 * @return String 81 * @author chh 82 * @May 23, 2012 83 */ 84 public static String toString(List<String> list) { 85 if (null == list || list.isEmpty()) 86 return ""; 87 StringBuffer sb = new StringBuffer(); 88 for (int i = 0; i < list.size(); i++) { 89 String str = (String) list.get(i); 90 if (i == list.size() - 1) { 91 sb.append(str); 92 } else { 93 sb.append(str + ","); 94 } 95 96 } 97 return sb.toString(); 98 } 99 100 /** 101 * 这种方法适合用来比较List中是否包含某个元素的问题 比较传入List list中是否含有与传入的String str相同的元素 102 * 103 * @param list 104 * @param str 105 * @return true 重复 false 不重复 106 * @throws Exception 107 */ 108 public static boolean isItEquals(List list, String str) { 109 for (int i = 0; i < list.size(); i++) { 110 if (str.equals(list.get(i).toString())) { 111 return true; 112 } 113 } 114 return false; 115 } 116 117 }
/** * <p>list操作的工具类</p> */public class ListUtil {/** * 过滤掉list里面才重复项 * * @param list * @return List */public static List<String> filterRepeat(List<String> list){int length = list.size();for(int i = 0;i < length - 1;i++){String temp = list.get(i).toString();for(int j = i + 1;j < length;j++){if(temp.equals(list.get(j))){list.remove(j);j--;length--;}}}return list;}/** * 判断list是否null或者长度为零,常用于从数据库取对象后的判断 * * @param list * @return true:空 false:非空 */public static boolean isNull(List list) {if (null == list || list.size() == 0) {return true;} else {return false;}}/** * list 是否有存在字符串value的值 * * @param list * 链表 * @param value * 值 * @return true: 存在,false:不存在 */public static boolean valueIsExit(List list, String value) {for (int i = 0; i < list.size(); i++) {if (value.equals(list.get(i).toString())) {return true;}}return false;}/** * 将list转化为数组 * @param list * @return */public static String[] toArray(List list) {if (null != list && !list.isEmpty()) {String[] arry = new String[list.size()];for (int i = 0; i < list.size(); i++) {arry[i] = list.get(i).toString();}return arry;}return null;
}/** * * 功能说明:将list 转化成字符串 例如 list={1,2,3}转化成1,2,3 * * @param list * @return String * @author chh * @May 23, 2012 */public static String toString(List<String> list) {if (null == list || list.isEmpty())return "";StringBuffer sb = new StringBuffer();for (int i = 0; i < list.size(); i++) {String str = (String) list.get(i);if (i == list.size() - 1) {sb.append(str);} else {sb.append(str + ",");}
}return sb.toString();}/** * 这种方法适合用来比较List中是否包含某个元素的问题 比较传入List list中是否含有与传入的String str相同的元素 * * @param list * @param str * @return true 重复 false 不重复 * @throws Exception */public static boolean isItEquals(List list, String str) {for (int i = 0; i < list.size(); i++) {if (str.equals(list.get(i).toString())) {return true;}}return false;}}
标签:equal end 存在 author rem 长度 sem equals str
原文地址:http://www.cnblogs.com/yujiwei/p/6884624.html