将string类型、integer类型的集合List、List转换成string字符串

1、将string类型集合List<String>转换成string字符串方法

 public static String listToString(List<String> stringList) {
        if (stringList == null) {
            return null;
        }
        StringBuilder result = new StringBuilder();
        boolean flag = false;
        for (String string : stringList) {
            if (flag) {
                result.append(",");
            } else {
                flag = true;
            }
            result.append(string);
        }
        return result.toString();
}

2、将integer类型集合List<Integer>转换成string字符串方法

public static Integer listToInteger(List<Integer> integerList) {
        if (integerList == null) {
            return null;
        }
        StringBuilder result = new StringBuilder();
        boolean flag = false;
        for (Integer integer : integerList) {
            if (flag) {
                result.append(",");
            } else {
                flag = true;
            }
            result.append(integer);
        }
        return result.length();
}

 

    原文作者:c_TOY
    原文地址: https://blog.csdn.net/sinat_15411661/article/details/89516126
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞