Java 将 List<Long> 转换为逗号分隔的字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33409592/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 14:38:50  来源:igfitidea点击:

Converting a List<Long> to comma separated string

javaarraylistapache-stringutils

提问by user2375298

Hi I am having a requirement where I need to convert Listof Longdatatype to comma separated String. Which would be the appropriate way. I have thought about using string builder or converting it to List<String>and then using StringUtilsjoin to get a String.

嗨,我有我需要转换的要求ListLong以逗号分隔的数据类型String。这将是适当的方式。我曾考虑使用字符串生成器或将其转换为List<String>然后使用StringUtilsjoin 来获取String.

I am looking for java 7solution,Not using guavaor java 8.

我正在寻找java 7解决方案,不使用guavajava 8

回答by Rahul Tripathi

You can try this:

你可以试试这个:

StringUtils.join(mylist, ',');

See org.apache.commons.lang3.StringUtils.

请参阅org.apache.commons.lang3.StringUtils