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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。