日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > java >内容正文

java

java listutils_Java的list自定义工具类ListUtils

發(fā)布時(shí)間:2024/7/5 java 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java listutils_Java的list自定义工具类ListUtils 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

/**

* 將list中map的key為ID的值作為KEY在套一層

*/

public static Map> keyToID(

List> datalist) {

Map> res = new HashMap>();

for (Map map : datalist) {

String id = map.get("ID");

res.put(id, map);

}

return res;

}

/**

* 移除List中所有Map的某個(gè)元素

*

* @param dataByOwnerList

* @param key

* @return

*/

public static List> removeMapElementInList(

List> dataList, String key) {

for (Map map : dataList) {

map.remove(key);

}

return dataList;

}

/**

* 將List類型map的value取出存入List>

*

* @param deallist

* @return

*/

public static List> getForlist(

List> deallist) {

List> list = new ArrayList>();

for (Map map : deallist) {

List list2 = new ArrayList(map.values());

list.add(list2);

}

return list;

}

/**

* 將List類型map的value取出存入List 如果value為null或者空字符串則為null

*

* @param deallist

* @return

*/

public static List getForlistString(

List> deallist) {

List list = new ArrayList();

for (Map map : deallist) {

for (Map.Entry string : map.entrySet()) {

String str = string.getValue();

if (str == null || str.length() <= 0) {

str = "null";

}

list.add(str);

}

}

return list;

}

/**

* 將list轉(zhuǎn)化為帶有左右括號(hào)的sql查詢條件語(yǔ)句,如 in (2,3,4)

*

* @author:mazhen

*/

public static String toSqlConditonalStatement(List list) {

if (null == list || list.size() == 0) {

try {

throw new Exception("因?yàn)閟ql查詢語(yǔ)句不能為空,所以傳入的list不能為空");

} catch (Exception e) {

e.printStackTrace();

}

}

StringBuffer conditionalStatement = new StringBuffer();

conditionalStatement.append("(");

for (String str : list) {

conditionalStatement.append(str);

conditionalStatement.append(",");

}

return conditionalStatement.toString().substring(0,

conditionalStatement.toString().length() - 1)

+ ")";

}

/**

* 判斷List里面有沒有重復(fù)的值

*

* @param list

* @return

*/

public static boolean isOverlap(List list) {

String temp = "";

for (int i = 0; i < list.size() - 1; i++) {

temp = list.get(i);

for (int j = i + 1; j < list.size(); j++) {

if (temp.equals(list.get(j))) {

return false;

// System.out.println("第" + (i + 1) + "個(gè)跟第" + (j + 1)

// + "個(gè)重復(fù),值是:" + temp);

}

}

}

return true;

}

/**

* 處理mapList中key為log_name的value,將value由路徑+名稱修改為僅有名稱

*

* @author : mazhen

*

* @param mapList

* @return

*/

public static List> deletePathOfLogName(

List> mapList) {

List> relist = new ArrayList>();

for (Map map : mapList) {

String pathAndName = map.get("log_name") + "";

String[] pathAndNames = pathAndName.split(";");

String names = "";

for (String str : pathAndNames) {

names += FileUtil.getFileNameFromPath(str) + ";";

}

names = names.substring(0, names.length() - 1);

map.put("log_name", names);

relist.add(map);

}

return relist;

}

/**

* 合并兩個(gè)list

*

* @return

*/

public static List sumList(List a, List b) {

List list = new ArrayList<>();

if (a != null && a.size() > 0) {

for (String string : a) {

list.add(string);

}

}

if (b != null && b.size() > 0) {

for (String string : b) {

list.add(string);

}

}

return list;

}

/**

* 合并兩個(gè)ListMap

*

* @return

*/

public static List> sumListMap(

List> listA, List> listB) {

List> list = new ArrayList>();

if (listA != null && listA.size() > 0) {

for (Map object : listA) {

list.add(object);

}

}

if (listB != null && listB.size() > 0) {

for (Map object : listB) {

list.add(object);

}

}

return list;

}

public static List> objectToString(

List> list) {

List> res = new ArrayList>();

for (Map map : list) {

res.add(MapUtil.objectToString(map));

}

return res;

}

/**

* 將查詢到的結(jié)果轉(zhuǎn)換成以key為鍵值的map,并將key從結(jié)果集中刪掉

* @param map

* @return

*/

public static Map ListToMapKeyId(List> map,String key,String value){

Map map1 = new HashMap();

if(map.isEmpty()){

return null;

}

for(int i = 0; i < map.size();i++){

Map idMap = new HashMap();

idMap = map.get(i);

try{

String id = String.valueOf(idMap.get(key));

if(value!=null&&!value.equals("")){

map1.put(id, idMap.get(value));

}else{

idMap.remove(key);

map1.put(id, idMap);

}

}catch(Exception e){

e.printStackTrace();

}

}

return map1;

}

//public static List> objectToString(

//List> list) {

//List> res = new ArrayList>();

//for (Map map : list) {

//res.add(MapUtil.objectToString(map));

//}

//return res;

//}

public static String ListToStrBySplit(String[] tableNameList, String split){

StringBuffer buf = new StringBuffer();

for(int i = 0; i < tableNameList.length;i++){

buf.append(tableNameList[i]);

if(i!=tableNameList.length-1){

buf.append(split);

}

}

return buf.toString();

}

public static String ListToStrBySplit(Object[] tableNameList, String split){

StringBuffer buf = new StringBuffer();

for(int i = 0; i < tableNameList.length;i++){

buf.append(tableNameList[i]);

if(i!=tableNameList.length-1){

buf.append(split);

}

}

return buf.toString();

}

public static Map ListMapToMap(List> list){

Map map = new HashMap();

if(list !=null && list.size()>0){

for(int i = 0; i < list.size();i++){

Map listMap = list.get(i);

Set sets = listMap.keySet();

for(String set:sets){

map.put((String) listMap.get(set), "Y");

}

}

}

return map;

}

總結(jié)

以上是生活随笔為你收集整理的java listutils_Java的list自定义工具类ListUtils的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。