How to Convert List to Csv String Format in Java


In this example we will show how to convert given list of strings to comma seperated values (csv) format.

Source Code

package com.beginner.examples;

import java.util.LinkedList;
import java.util.List;
 
public class List2CsvExample {
    
    public static void main(String a[]){
         
        List list = new LinkedList();
        list.add("1");
        list.add("2");
        //use String.join() to join list with specify separator
        String result = String.join(",",list);
        System.out.println(result);
    }
}

Output:

1,2

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments