How to Convert an Array to Comma Separated String in Java - Example Tutorial

The simplest way to convert an array to comma separated String is to create a StringBuilder, iterate through the array, and add each element of the array into StringBuilder after appending the comma. You just need Java 1.5 for that, even if you are not running on Java 5, you can use StringBuffer in place of StringBuilder. The joining of String has got even easier in JDK 8, where you have got the join() method right in the String class itself. The join() method takes a delimiter and a source, which can be an array or collection, and returns a String where each element is joined by a delimiter.

تعليقات

المشاركات الشائعة من هذه المدونة

Why use Underscore in Numbers from Java? Underscore in Numeric Literals Example

3 ways to convert String to Boolean in Java? Examples

Coursera's TensorFlow: Advanced Techniques Specialization Review [2022]