Sunday, May 10, 2026
HomeLanguagesJavaHow to Convert a String to ArrayList in Java?

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.

Parameters:

  • regex – a delimiting regular expression
  • Limit – the resulting threshold

Returns: An array of strings computed by splitting the given string.

Throws: PatternSyntaxException – if the provided regular expression’s syntax is invalid.  

Approach:

  • Splitting the string by using the Java split() method and storing the substrings into an array.
  • Creating an ArrayList while passing the substring reference to it using Arrays.asList() method.

Java




// Java program to convert String to ArrayList
  
import java.util.ArrayList;
import java.util.Arrays;
  
public class Main {
  
    public static void main(String[] args)
    {
  
        String str = "Geeks";
  
        // split string by no space
        String[] strSplit = str.split("");
  
        // Now convert string into ArrayList
        ArrayList<String> strList = new ArrayList<String>(
            Arrays.asList(strSplit));
  
        // Now print the ArrayList
        for (String s : strList)
            System.out.println(s);
    }
}


Output

G
e
e
k
s
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS