splitToList(CharSequence sequence)方法將序列拆分為字符串成分,並將其作為不可變列表返回。
用法:
public List<String> splitToList(CharSequence sequence)
參數:此方法將序列作為參數,即要分割的字符序列。
返回值:此方法返回從參數分割的分段的不可變列表。
以下示例說明了splitToList()方法的用法方式:
範例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
範例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
相關用法
- Java Guava Splitter limit()用法及代碼示例
- Java Guava Splitter trimResults()用法及代碼示例
- Java Guava Splitter omitEmptyStrings()用法及代碼示例
- Java Guava Splitter fixedLength()用法及代碼示例
- Java Guava Doubles.min()用法及代碼示例
- Java Guava Shorts.max()用法及代碼示例
- Java Guava Floats.max()用法及代碼示例
- Java Guava Chars.min()用法及代碼示例
- Java Guava Doubles.max()用法及代碼示例
- Java Guava Chars.max()用法及代碼示例
- Java Guava Longs.max()用法及代碼示例
- Java Guava Floats.min()用法及代碼示例
- Java Guava Shorts.contains()用法及代碼示例
注:本文由純淨天空篩選整理自Sahil_Bansall大神的英文原創作品 Splitter splitToList() method | Guava | Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。