标签:ati rgs spl lis static item stat main 爸爸
public class SplitterTest { public static void main(String args[]){ //1、拆分字符串为List集合 String str="小小,妈妈,爸爸,爷爷,奶奶"; Splitter splitter =Splitter.on(","); List<String> list=splitter.splitToList(str); System.out.println(list); //输出:[小小, 妈妈, 爸爸, 爷爷, 奶奶] //2、忽略空字符 String str1="a,b,c,d,,f,g"; //omitEmptyStrings()代表去除空字符串 List<String> list1=Splitter.on(",").omitEmptyStrings().splitToList(str1); System.out.println(list1); //输出:[a, b, c, d, f, g] //3、忽略空字符且去除字符串前后空格 String str2="a,b,c,d,,f, g "; List<String> list2=Splitter.on(",").omitEmptyStrings().trimResults().splitToList(str2); System.out.println(list2); //输出:[a, b, c, d, f, g] } }
guava字符串工具 Splitter 主要功能是拆分字符串为集合 Map
标签:ati rgs spl lis static item stat main 爸爸
原文地址:https://www.cnblogs.com/jiaowoxiaofeng/p/11966707.html