How to Convert a Comma-Separated String into an ArrayList in Java? Last Updated : 16 Nov, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In Java, to convert a comma-separated string into ArrayList, we can use the split() method to break the string into an array based on the comma delimiter. Another method we can also use Java Streams for a functional approach to achieve the same result.Example:Input: "Hello,from,geeks,for,geeks"Output: [Hello, from, geeks, for, geeks]1. Using split() MethodThe code initializes a string s.Then the code uses split() method on the string s and passes `,` separator in the method argument.The split() returns an array.Arrays.asList() is used to create a List from the array.new ArrayList<>() constructs a new ArrayList with the elements from the list.In the end, the code prints the ArrayList.Illustration: Java // Java program to Convert a Comma-Separated // String into an ArrayList using split() import java.util.*; class GFG { public static void main(String[] args) { String s = "Hello,from,geeks,for,geeks"; // split the string by comma String[] arr = s.split(","); // Convert the array into arraylist ArrayList<String> l = new ArrayList<>(Arrays.asList(arr)); System.out.println("The ArrayList is: " + l); } } OutputThe ArrayList is: [Hello, from, geeks, for, geeks] 2. Using Java StreamsThe code initializes a string s.The code split() the input string into an array of strings using the comma`,` as a delimiter. The split() returns an array of substring.Arrays.stream() converts the array of substrings into a stream of strings..collect(Collectors.toCollection(ArrayList :: new)) - This will collect the stream of strings into a new ArrayList through the collector. All the collected elements should be stored in an ArrayList.Illustration: Java // Java Program to Convert a Comma-Separated // String into an ArrayList Using Stream import java.util.*; import java.util.stream.Collectors; class GFG { public static void main(String[] args) { String s = "Hello,from,geeks,for,geeks"; // Split the string by comma and collect into ArrayList ArrayList<String> l = Arrays.stream(s.split(",")).collect(Collectors.toCollection(ArrayList::new)); System.out.println("The ArrayList is: " + l); } } OutputThe ArrayList is: [Hello, from, geeks, for, geeks] Comment More infoAdvertise with us Next Article How to Convert a Comma-Separated String into an ArrayList in Java? P priyasha2323 Follow Improve Article Tags : Java Java Programs Java-Strings Java-ArrayList Practice Tags : JavaJava-Strings Similar Reads Convert ArrayList to Comma Separated String in Java ArrayList is a part of collection framework and is present in java.util package. It provides us with dynamic arrays in Java. In order to convert ArrayList to a comma-separated String, these are the approaches available in Java as listed and proposed below as follows: Earlier before Java 8 there were 5 min read How to Convert an ArrayList into a JSON String in Java? In Java, an ArrayList is a resizable array implementation of the List interface. It implements the List interface and is the most commonly used implementation of List. In this article, we will learn how to convert an ArrayList into a JSON string in Java. Steps to convert an ArrayList into a JSON str 2 min read How to Convert a String to ArrayList in Java? Converting String to ArrayList means each character of the string is added as a separator character element in the ArrayList. Example: Input: 0001 Output: 0 0 0 1 Input: Geeks Output: G e e k s We can easily convert String to ArrayList in Java using the split() method and regular expression. Paramet 1 min read How to Convert Comma Separated String to HashSet in Java? Given a Set of String, the task is to convert the Set to a comma-separated String in Java. Examples: Input: Set<String> = ["Geeks", "ForGeeks", "GeeksForGeeks"] Output: "Geeks, For, Geeks" Input: Set<String> = ["G", "e", "e", "k", "s"] Output: "G, e, e, k, s" There are two ways in which 2 min read Convert a List of String to a comma separated String in Java Given a List of String, the task is to convert the List to a comma separated String in Java. Examples: Input: List<String> = ["Geeks", "ForGeeks", "GeeksForGeeks"] Output: "Geeks, For, Geeks" Input: List<String> = ["G", "e", "e", "k", "s"] Output: "G, e, e, k, s" Approach: This can be ac 1 min read Like