逗号分隔的字符串与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.而且大多数情况下,好多“别人”都实现了这个功能.程序员有不得不在这其中选择.大部分情况下 ...
随机推荐
- jQuery EasyUI 折叠面板accordion的使用实例
1.对折叠面板区域 div 设置 class=”easyui-accordion” 2.在区域添加多个 div, 每个 div 就是一个面板 (每个面板一定要设置 title 属性). 3.设置面板属 ...
- 补充:pyhton 2 和3中的beyts类型
在python2里,bytes == str python2里还有个单独的类型是unicode , 把字符串解码后,就会变成unicode. 既然python2中byets == str,那为什么还要 ...
- C# Note12:WPF只允许数字的限制性TextBox
在使用中,我们经常遇到文本框中只允许输入数字(整型数或浮点数...) 的情况,如果我们输入特殊字符(字母和符号...),在获取其输入值时,如果先做判断或其他处理,会直接导致application发生c ...
- springmvc配置文件
1 springMVC的配置文件路径问题 https://www.cnblogs.com/ysloong/p/6071450.html
- If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
学习Spring Boot 过程中遇到了下列这个问题 Description: Failed to configure a DataSource: 'url' attribute is not spe ...
- Django 2.11 静态页面404 解决
在settings中配置 STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(BASE_DIR,"static"), ...
- 18个Python高效编程技巧,Mark!
初识Python语言,觉得python满足了我上学时候对编程语言的所有要求.python语言的高效编程技巧让我们这些大学曾经苦逼学了四年c或者c++的人,兴奋的不行不行的,终于解脱了.高级语言,如果做 ...
- JDK 12 & JAVA
JDK 12 & JAVA js style https://github.com/winterbe https://winterbe.com/posts/2018/09/24/java-11 ...
- 十、docker扩展
一.memcached docker pull memcached docker run --name my-memcache -d -p 11211:11211 memcached telnet 1 ...
- How to install rime on Debian
apt-get install ibus ibus-rime librime-data-wubi reboot cp ~/.config/ibus/rime/default.yaml ~/.confi ...