-
List转换为字符串并添加分隔符
- public String listToString(List list, char separator) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < list.size(); i++) {
- sb.append(list.get(i)).append(separator);
- }
- return list.isEmpty()?"":sb.toString().substring(0, sb.toString().length() - 1);
- }
-
- public String listToString2(List list, char separator) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < list.size(); i++) {
- if (i == list.size() - 1) {
- sb.append(list.get(i));
- } else {
- sb.append(list.get(i));
- sb.append(separator);
- }
- }
- return sb.toString();
- }
-
- public String listToString3(List list, char separator) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < list.size(); i++) {
- sb.append(list.get(i));
- if (i < list.size() - 1) {
- sb.append(separator);
- }
- }
- return sb.toString();
- }
-
- public class Separator {
- private String next = "";
- private String separator;
-
- public Separator(String separator) {
- this.separator = separator;
- }
-
- public String get() {
- String result = next;
- next = separator;
- return result;
- }
- }
-
- public String listToString4(List<String> list, Separator separator) {
- StringBuilder sb = new StringBuilder();
- for (String s : list) {
- if (s != null && !"".equals(s)) {
- sb.append(separator.get()).append(s);
- }
- }
- return sb.toString();
- }
-
- public String listToString5(List list, char separator) {
- return org.apache.commons.lang.StringUtils.join(list.toArray(),separator);
- }
-
相关阅读:
- viewDidLoad 和
C#实现excel导入到sql server 2008(.net版)
Windows PE 第十章 加载配置信息
Windows PE第九章 线程局部存储
Windows PE第九章 线程局部存储
Windows PE 第八章 延迟加载导入表
Windows PE 第八章 延迟加载导入表
Windows PE资源表编程(枚举资源树)
Windows PE资源表编程(枚举资源树)
欺骗的艺术-读后总结
-
原文地址:https://www.cnblogs.com/mr-wuxiansheng/p/8245037.html
Copyright © 2020-2023
润新知