如何相互转换逗号分隔的字符串和List

直接上代码:

  

    public static void main(String[] args) {
        
        //字符串转list
        String strs = "a,b,c";  
        List<String> result = Arrays.asList(strs.split(","));  
        System.out.println(result);
        
        //list转字符串分隔
        List<String> list = new ArrayList<String>();  
        list.add("a");  
        list.add("b");  
        list.add("c");  
        String[] aaaa={"a","b","c"};
        //来自谷歌com.google.common.base.Joiner guava
        String str = Joiner.on(",").join(aaaa);  
        
        System.out.println(str);
    }

 

posted @ 2017-09-29 20:22  全力以赴001  阅读(1476)  评论(0编辑  收藏  举报