List will turn into a Java array scheme comma

List will turn into a Java array scheme comma

Description: Comma turn string into an array or List are possible, which in turn is still possible; but if you turn List List, basic misunderstanding in Java 7 only for loop, if the Java 8 Lambda expressions can be used to achieve, here will be omitted the step of realization, apart from the near future would include the definition of implementation tools.

Level 3 heading

Method 1: Using Arrays class of JDK

String str = "a,b,c";  
List<String> result = Arrays.asList(str.split(","));

Method 2: using the Guava Splitter

String str = "a, b, c";  
List<String> result = Splitter.on(",").trimResults().splitToList(str);  

Method 3: Use of the StringUtils Apache Commons (except the split)

String str = "a,b,c";  
List<String> result = Arrays.asList(StringUtils.split(str,","));   

Method 4: Using the StringUtils Spring Framework

String str = "a,b,c";  
List<String> str = Arrays.asList(StringUtils.commaDelimitedListToStringArray(str));  

List converted to a comma separator

Method 1: Use JDK (if there is no good way, need step by step to achieve)

for... 

Method 2: using the Guava Joiner

List<String> list = new ArrayList<String>();  
list.add("a");  
list.add("b");  
list.add("c");  
String str = Joiner.on(",").join(list);  

Method 3: Using the Apache Commons StringUtils

List<String> list = new ArrayList<String>();  
list.add("a");  
list.add("b");  
list.add("c");  
String str = StringUtils.join(list.toArray(), ",");  

Method 4: Using the StringUtils Spring Framework

List<String> list = new ArrayList<String>();  
list.add("a");  
list.add("b");  
list.add("c");  
String str = StringUtils.collectionToDelimitedString(list, ",");  
Published 30 original articles · won praise 8 · views 20000 +

Guess you like

Origin blog.csdn.net/wg22222222/article/details/82867265