逗号分隔的字符串与List互转
将逗号分隔的字符串转换为List
// 将逗号分隔的字符串转换为List
String str = "a,b,c";
// 1.使用JDK,逗号分隔的字符串-->数组-->list
List<String> result = Arrays.asList(str.split(","));
// 2.使用Apache Commons的StringUtils
List<String> result1 = Arrays.asList(StringUtils.split(str, ","));
// 3.通过遍历
String[] strings = str.split(",");
List<String> result2 = new ArrayList<String>();
for (String string : strings) {
result2.add(string);
}
将List转换为逗号分隔的字符串
// 将List转换为逗号分隔的字符串
List<String> list = new ArrayList<String>();
list.add("a");
list.add("b");
list.add("c");
// 1.使用Apache Commons的StringUtils
String str1 = StringUtils.join(list.toArray(), ",");
// 2.通过遍历
StringBuffer str2 = new StringBuffer();
for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) {
String string = (String) iterator.next();
str2.append(string);
if(iterator.hasNext()){
str2.append(",");
}
}
Apache Commons的StringUtils下载: http://download.csdn.net/download/xc_oo0/9988044
http://commons.apache.org/proper/commons-lang/download_lang.cgi参考文章: https://www.cnblogs.com/hui-blog/p/6375174.html
逗号分隔的字符串与List互转的更多相关文章
- 将逗号分隔的字符串与List互转
将逗号分隔的字符串与List互转 方法 1: 利用JDK的Arrays类String str = "a,b,c";List<String> result = Array ...
- 逗号分隔的字符串转换为行数据(collection)(续)
逗号分隔的字符串转行数据的存储过程一个: CREATE OR REPLACE FUNCTION SP_YX_SPLIT ( p_list CLOB, p_sep VARCHAR2 := ',' ) R ...
- 逗号分隔的字符串转换为行数据(collection)
逗号分隔的字符串转换为行数据(collection) CREATE OR REPLACE FUNCTION "GET_STR_TAB" (v_str in varchar2) re ...
- MYSQL查询某字段中以逗号分隔的字符串的方法
首先我们建立一张带有逗号分隔的字符串. CREATE TABLE test(id int(6) NOT NULL AUTO_INCREMENT,PRIMARY KEY (id),pname VARCH ...
- 如何相互转换逗号分隔的字符串和List
将逗号分隔的字符串转换为List 方法 1: 利用JDK的Arrays类 [java] view plain copy ico_fork.svg1.5 KB String str = " ...
- 将逗号分隔 的字符串转化成List
将逗号分隔 的字符串转化成List List<String> parIdListTmp = new ArrayList<String>(); String parIdArray ...
- mysql判断表里面一个逗号分隔的字符串是否包含单个字符串、查询结果用逗号分隔
1.mysql判断表里面一个逗号分隔的字符串是否包含单个字符串 : FIND_IN_SET select * from tablename where FIND_IN_SET(传的参数,匹配字段) 例 ...
- <c:forEach>可以默认的把以逗号分隔的字符串作为一个集合来遍历
<c:forEach>可以默认的把以逗号分隔的字符串作为一个集合来遍历
- List与逗号分隔的字符串相互转换
如果程序员想实现某种功能,有两条路可以走.一条就是自己实现,一条就是调用别人的实现,别人的实现就是所谓的API.而且大多数情况下,好多“别人”都实现了这个功能.程序员有不得不在这其中选择.大部分情况下 ...
随机推荐
- Java8 Lambda和Stream的用法
package com.zhangxueliang.demo; import java.util.ArrayList; import java.util.List; import java.util. ...
- 在linux上安装MySQL数据库,并简单设置用户密码,登录MySQL
在新装的Centos系统上安装MySQL数据库. <p><a href="http://www.cnblogs.com/tijun/">提君博客原创< ...
- js中style,currentStyle和getComputedStyle的区别以及获取css样式操作方法
用js的style只能获取元素的内联样式,内部样式和外部样式使用style是获取不到的. currentStyle可以弥补style的不足(可获取内联样式,内部样式和外部样式),但是只适用于IE. g ...
- web项目中的监听器,过滤器以及自定义servlet的执行顺序
可以看到web容器一启动就会实例化监听器的contextInitialized(ServletContextEvent event)方法,然后是过滤器的init()方法,最后在用户访问web应用的 时 ...
- java 静态成员访问
public class MqConfig { @Getter private static IProducerProcessor callBackProducerRetry; @Getter @Va ...
- JMeter 连接 sql server
1.安装驱动 http://www.microsoft.com/zh-CN/download/details.aspx?id=11774 下载后解压后复制sqljdbc.jar到 “jmeter的安装 ...
- vue-cli: render:h => h(App)是什么意思
import Vue from 'vue' import App from './App.vue' Vue.config.productionTip = false new Vue({ render: ...
- PHP通过循环给数组赋值
$userDatas = [ ['user_id'=>1], ['user_id'=>3] ]; $userIds = []; foreach ($userDatas as $item){ ...
- js4
数组的解构赋值: 位置对象的解构赋值: 名称 // {}在解构赋值的时候,不能出现在一行的最前面,否则js解析器会把他当成一个代码块,加()({a, b} = obj),告诉他这个仅仅是一个解构语句 ...
- How to enable AHCI on Windows7
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\msahci