You could do this:

String str = "...";
List<String> elephantList = Arrays.asList(str.split(", "));

In Java 9+, create an unmodifiable list with List.of.

List<String> elephantList = List.of(str.split(", "));  // Unmodifiable list. 

Basically the .split() method will split the string according to (in this case) delimiter you are passing and will return an array of strings.

However, you seem to be after a List of Strings rather than an array. So the array must be turned into a list. We can turn that array into a List object by calling either Arrays.asList() or List.of.


FYI you could also do something like so:

String str = "...";
ArrayList<String> elephantList = new ArrayList<>(Arrays.asList(str.split(","));

But it is usually better practice to program to an interface rather than to an actual concrete implementation. So I would not recommend this approach.

Answer from npinti on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-split-string-by-comma
Java - Split String by Comma - GeeksforGeeks
July 23, 2025 - In Java, splitting a string by a comma is commonly achieved using the split() method of the String class. This method takes a regular expression as an argument and returns an array of substrings split at each match of the regex.
🌐
BeginnersBook
beginnersbook.com › 2022 › 09 › java-code-to-split-string-by-comma
Java Code to Split String by Comma
In this program, the string is entered by user, which we will capture using Scanner class. import java.util.Scanner; public class JavaExample { public static void main(String[] args) { String str; //getting the string from user System.out.println("Enter a string that contains commas: "); Scanner scan = new Scanner(System.in); str = scan.nextLine(); String[] strArray = str.split(","); System.out.println("Split result: "); for(String s: strArray){ System.out.println(s); } } }
🌐
Blogger
javarevisited.blogspot.com › 2015 › 12 › how-to-split-comma-separated-string-in-java-example.html
How to split a comma separated String in Java? Regular Expression Example
You can use the split() function to parse comma-delimited String. Just remember that it takes regular expression but to break CSV string, you just need to pass "," if your String is like "a,b,c" i.e. there is no space between two values.
🌐
Medium
medium.com › @AlexanderObregon › splitting-a-string-by-comma-in-java-the-right-way-1d3aa2aff1fa
Splitting a String by Comma in Java the Right Way | Medium
June 26, 2025 - It takes a string argument that’s treated as a regular expression and breaks up the original string using whatever matches that pattern. ... That gives you an array with three values: "alpha", "beta", and "gamma". The split works here because the comma doesn't carry any special behavior in regular expressions, so Java reads it as just another character in the string.
🌐
Java67
java67.com › 2016 › 01 › how-to-split-string-by-comma-in-java-with-example.html
How to split String by comma in Java - Example Tutorial | Java67
Here is our sample Java program to demonstrate how you can use the split() method of java.lang.String class to break a CSV string into words. In our example, we have a String where programming languages are separated by the comma.
🌐
TutorialsPoint
tutorialspoint.com › split-string-with-comma-in-java
Split String with Comma (,) in Java
Let’s say the following is our string.String str = " This is demo text, and demo line!";To split a string with comma, use the split() method in Java.str.split("[,]", 0);The following is the complete example.Example Live Demopublic class Demo { pu
🌐
Baeldung
baeldung.com › home › java › java string › convert a comma separated string to a list in java
Convert a Comma Separated String to a List in Java
September 3, 2025 - Even though both these functions ... created by adjoining separators, while the split method ignores the empty strings. So, if we have empty strings that we want to be included in our list, then we should use the splitPreserveAllTokens instead of split. Finally, we’ll use the Guava library to convert our strings to their appropriate lists. To convert our countries string, we’ll first call Splitter.on with a comma as the parameter ...
Find elsewhere
🌐
Delft Stack
delftstack.com › home › howto › java › java split string by comma
How to Split a Comma-Separated String in Java | Delft Stack
February 2, 2024 - Nevertheless, the one thing different here is the approach to the solution, which is using ArrayList<String> instead of just List<String>. ... It’s not that hard. The list is an interface, while an ArrayList is a Java collection class. The former provides a static array, while the latter generates a dynamic array to store the elements. ... // Example 2 using ArrayLists and split method import java.util.ArrayList; import java.util.Arrays; public class ArrayListSplitMethod { public static void main(String[] args) { String ALstr = "So,many,ways,to,separate,a,string,from,a,specified,position"; ArrayList<String> Spliter = new ArrayList<>(Arrays.asList(ALstr.split(","))); Spliter.forEach(System.out::println); } }
🌐
Guru99
guru99.com › home › java tutorials › split() string method in java: how to split string with example
Split() String Method in Java: How to Split String with Example
December 26, 2023 - So we will get five separate strings as follows: ... Use the string split in Java method against the string that needs to be divided and provide the separator as an argument. In this Java split string by delimiter case, the separator is a comma ...
🌐
Quora
quora.com › How-do-I-split-a-string-in-Java-and-display-it-with-commas
How to split a string in Java and display it with commas - Quora
Answer (1 of 5): Use the built-in split function using the delimiting pattern of your needs and, store that in an array, then print it the way you like or use a range loop straightaway. You could also straight away print it. [code]String something = "Blah blah blah blah"; System.out.println(Arr...
🌐
Coderanch
coderanch.com › t › 451685 › java › split-String-array-comma-seperated
How to split String array which has comma seperated values (Beginning Java forum at Coderanch)
You could use java.util.Scanner. This will iterate through each number as it finds them, as opposed to String.split(), which will hold all the numbers in memory in one giant array. ... Another option... instead of using the regex split() method, you could use the regex find() method. With find(), you can defined the token to include, up to 999 values separated by commas -- and hence, no need to split and remerge 999 items.
🌐
Baeldung
baeldung.com › home › java › java string › split a string in java
Split a String in Java | Baeldung
January 8, 2024 - Splitting Strings is a very frequent ... in Java. Let’s start with the core library – the String class itself offers a split() method – which is very convenient and sufficient for most scenarios. It simply splits the given String based on the delimiter, returning an array of Strings. Let us look at some examples. We’ll start with splitting by a comma...
🌐
GeeksforGeeks
geeksforgeeks.org › java › split-a-string-in-java-with-delimiter
How to Split a String in Java with Delimiter? - GeeksforGeeks
July 23, 2025 - Here is a simple program to split a string with a comma delimiter in Java using the split() method:
🌐
Blogger
javarevisited.blogspot.com › 2017 › 01 › how-to-split-string-based-on-delimiter-in-java.html
How to Split String based on delimiter in Java? Example Tutorial
This is similar to the earlier example but it's more common because CSV is a popular format to export data from databases, tables, or XLS files. You can split a comma-delimited String by passing "," to split() method as shown in the following ...
🌐
Baeldung
baeldung.com › home › java › java string › java string.split()
Java.String.split() | Baeldung
March 12, 2025 - This method helps us break a string into smaller pieces, based on a specified delimiter. A delimiter is a character or a sequence of characters that mark the boundaries between the pieces.
🌐
Briebug Blog
blog.briebug.com › blog › java-split-string
Using the Java String.split() Method
First, we initialize a String variable, ourString to "This,is,a,comma,separated,string". Next, is where the magic happens. We declare a String array, ourStringSplitArray and set it's value by calling the split() method on ourString.