How can I convert List<Integer> to String
? E.g. If my List<Integer>
contains numbers 1 2 and 3 how can it be converted to String = "1,2,3"? Every help will be appreciated.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Just to add another (of many) options from a popular library (Apache Commons):
See documentation: https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html#join-java.lang.Iterable-java.lang.String-
An elegant option from others' comments (as of Java 8):
In vanilla Java 8 (streams) you can do
I think you may use simply
List.toString()
as below:If you don't want
[]
in the string, simply use the substring e.g.:Please note:
List.toString()
usesAbstractCollection#toString
method, which converts the list into String as aboveWith Guava:
One way would be:
Iterate
over list, add each item toStringBuffer
(or)StringBuilder
and dotoString()
at end.Example: