代碼以下:javascript
import com.alibaba.fastjson.JSON; import com.google.common.base.Joiner; import com.google.common.collect.Lists; import com.google.common.base.Splitter; List<String> list = Lists.newArrayList("a","b","c"," "); String s = Joiner.on(",").join(list); // 以逗號分割 System.out.println(s); // a,b,c, // 去先後空格&&去空string Splitter split = Splitter.on(',').trimResults().omitEmptyStrings(); List<String> list1 = split.splitToList(s); System.out.println(JSON.toJSONString(list1)); // ["a","b","c"]