将逗号分隔值转换为列表< Long> [英] Convert Comma Separated Values to List<Long>
本文介绍了将逗号分隔值转换为列表< Long>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一组数字,例如 1,2,3,4,5,6,7
输入为单个字符串
。我想将这些数字转换为 List
的 Long
对象,即 List< Long>
。
Assume I have a set of numbers like 1,2,3,4,5,6,7
input as a single String
. I would like to convert those numbers to a List
of Long
objects ie List<Long>
.
有人可以推荐最简单的方法吗?
Can anyone recommend the easiest method?
推荐答案
我会使用优秀的谷歌的Guava库来做到这一点。 String.split可能会造成很多麻烦。
I would use the excellent google's Guava library to do it. String.split can cause many troubles.
String numbers="1,2,3,4,5,6,7";
Iterable<String> splitIterator = Splitter.on(',').split(numbers);
List<String> list= Lists.newArrayList(splitIterator );
这篇关于将逗号分隔值转换为列表< Long>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文