码迷,mamicode.com
首页 > 编程语言 > 详细

java字符串与字符串数组的转换

时间:2018-05-25 22:53:45      阅读:455      评论:0      收藏:0      [点我收藏+]

标签:void   []   auto   转换   str   spl   ring   color   public   

处理csv文件时,经常需要将字符串转为字符串数组,也需要将字符串数组转换为字符串。

晚上研究了字符串相关函数,用split函数和join函数可以实现。

如下:

public class Testlist {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String s = "1,2,3";
                // 字符串转为字符串数组使用split函数
        String[] s_array=s.split(",");
        for (String string : s_array) {
            System.out.println(string);
        }
        s_array[0]="234";
        String delimetal=",";
                // 字符串数组转为字符串用String.join函数
        System.out.println(String.join(delimetal, s_array));

    }

}

 

java字符串与字符串数组的转换

标签:void   []   auto   转换   str   spl   ring   color   public   

原文地址:https://www.cnblogs.com/eagle-1024/p/9090877.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!