Monday, June 8, 2026
HomeLanguagesJavaSplitter splitToList() method | Guava | Java

Splitter splitToList() method | Guava | Java

The method splitToList(CharSequence sequence) splits sequence into string components and returns them as an immutable list.

Syntax:

public List<String> 
    splitToList(CharSequence sequence)

Parameters: This method takes sequence as parameter which is the sequence of characters to split.

Return Value: This method returns an immutable list of the segments split from the parameter.

Below examples illustrate the working of splitToList() method:

Example 1:




// Java code to show implementation of
// splitToList method
// of Guava's Splitter Class
  
import com.google.common.base.Splitter;
import java.util.List;
  
class GFG {
  
    // Driver's code
    public static void main(String[] args)
    {
  
        // Creating a string variable
        String str = "Hello, geeks, for, geeks, noida";
  
        // SplitToList returns a List of the strings.
        // This can be transformed to an ArrayList
        // or used directly in a loop.
        List<String> myList = Splitter.on(',').splitToList(str);
  
        for (String temp : myList) {
            System.out.println(temp);
        }
    }
}


Output:

Hello
 geeks
 for
 geeks
 noida

Example 2:




// Java code to show implementation of
// splitToList method 
// of Guava's Splitter Class
  
import com.google.common.base.Splitter;
import java.util.List;
  
class GFG {
  
    // Driver's code
    public static void main(String[] args)
    {
  
        // Creating a string variable
        String str = "Everyone. should. Learn, Data. Structures";
  
        // SplitToList returns a List of the strings.
        // This can be transformed to an ArrayList
        // or used directly in a loop.
        List<String> myList = Splitter.on('.').splitToList(str);
  
        for (String temp : myList) {
            System.out.println(temp);
        }
    }
}


Output:

Everyone
 should
 Learn, Data
 Structures
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6895 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7018 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS