逗号分隔的字符串与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.而且大多数情况下,好多“别人”都实现了这个功能.程序员有不得不在这其中选择.大部分情况下 ...
随机推荐
- Azure系列2.1 —— com.microsoft.azure.storage.blob
网上azure的资料较少,尤其是API,全是英文的,中文资料更是少之又少.这次由于公司项目需要使用Azure,所以对Azure的一些学习心得做下笔记,文中不正确地方请大家指正. Azure Blob ...
- 逻辑斯特回归tensorflow实现
calss #!/usr/bin/python2.7 #coding:utf-8 from __future__ import print_function import tensorflow as ...
- MyBatis映射文件5
返回map Map<String,Object> getEmpByResMap(Integer id); <select id="getEmpByResMap&qu ...
- 排查 Maxwell can not find database 并且使用 MySQL binlog 解决相关问题
目前我们在使用 Maxwell 在读线上机器的 binlog 同步我们的离线数据库. 这次错误定位上,首先线要确定问题是发生在生产者 还是队列 还是消费者.经过查看各机器上任务的运行日志,定位到了问题 ...
- Python的web编程
1.urlparse模块 urlparse.urlparse() 将一个url转化为(prot_sch, net_loc, path, params, query, frag)的元组 url ...
- vue 響應接口
全局方式: 增加屬性和set()和get(): vue.set(targname,key,vaule) targname:對象名或者數組名 key:字符串 value:任何值 刪除屬性和set()和g ...
- SpringJdbc框架
import javax.sql.DataSource; import org.springframework.jdbc.core.JdbcTemplate; import JdbcUtils.Jdb ...
- php1
正则表达式 $p = '/name:(\w+\s?\w+)/'; $str = "name:steven jobs"; preg_match($p, $str, $match); ...
- MySQL in型子查询陷阱
现在有两个表,table1和table2,table1有1千万数据(id 主键索引),table2有三条数据(uid字段 3,5,7): select * from table1 where id i ...
- springmvc拦截器匹配规则