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); } } } |
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); } } } |
Everyone should Learn, Data Structures
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Splitter trimResults() method | Guava | Java
- Splitter omitEmptyStrings() method | Guava | Java
- Splitter limit() method | Guava | Java
- Splitter fixedLength() method | Guava | Java
- Splitter withKeyValueSeparator(char separator) method | Guava | Java
- Splitter Class | Guava | Java
- Java Guava | Chars.contains() method with Examples
- Java Guava | Doubles.max() method with Examples
- Java Guava | Chars.max() method with Examples
- Java Guava | Floats.max() method with Examples
- Java Guava | Floats.contains() method with Examples
- Java Guava | Doubles.contains() method with Examples
- Java Guava | Doubles.min() method with Examples
- Java Guava | Longs.max() method with Examples
- Java Guava | Shorts.min() method with Examples
- Java Guava | Longs.contains() method with Examples
- Java Guava | Chars.min() method with Examples
- Java Guava | Floats.min() method with Examples
- Java Guava | Bytes.contains() method with Examples
- Java Guava | pow(int b, int k) method of IntMath Class
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

