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

处理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));

    }

}

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

时间: 2024-08-30 14:41:14

java字符串与字符串数组的转换的相关文章

16进制值字符串与byte数组的转换

/** * 将byte数组转换为表示16进制值的字符串, 如:byte[]{8,18}转换为:0813, 和public static byte[] * hexStr2ByteArr(String strIn) 互为可逆的转换过程 * * @param arrB * 需要转换的byte数组 * @return 转换后的字符串 * @throws Exception * 本方法不处理任何异常,所有异常全部抛出 */ public static String byteArr2HexStr(byte[

1.7 字符串和字符数组的转换

package Demo; public class Demo2 { public static void main(String[] args) {  String str = "helloworld";  char c[] = str.toCharArray(); //字符串转换为字符数组  for(int x=0;x<c.length;x++){   System.out.println(c[x]+".");   } /*h.  e.  l.  l.  

Java 复习 —— 集合与数组的转换

前言: 很多时候,你会觉得数组使用方便,有些时候你会觉得集合使用更加方便,你们对于集合和数组的转换那就在所难免了,下面总结一下数组与集合的转换. 1.把数组转为集合 Arrays.asList()  1)网上解释 在使用Arrays.asList()后调用add,remove这些method时出现 java.lang.UnsupportedOperationException 异常.这是由于Arrays.asList() 返回java.util.Arrays$ArrayList, 而不是Arra

字符串与字符数组的转换

String str  = "helloworld"; char data[] =  str.toCharArray(); for(int x = 0 ; x< data.length ;x++) { data[x] -= 32 ;   // 小写变大写 System.out.print(data[x] + ","); } System.out.print(new String(data)); // 全部转换 System.out.print(new Stri

字符串与字节数组的转换

String str = "helloworld"; byte data[] = str.getBytes(); for(int x = 0 ; x < data.length ; x++) { data[x]- = 32 ; System.out.print(datd[x] + ','); } System.out.println(new String(data)); 通过程序可以发现,字节并不适合处理中文.字符适合处理中文,字节适合处理二进制数据. 字符串比较 如下的比较操作

Java 图片与byte数组互相转换

1 //图片到byte数组 2 public byte[] image2byte(String path){ 3 byte[] data = null; 4 FileImageInputStream input = null; 5 try { 6 input = new FileImageInputStream(new File(path)); 7 ByteArrayOutputStream output = new ByteArrayOutputStream(); 8 byte[] buf =

字符串和字符数组之间的转换

package String; /* * 写了一个字符串和字符数组之间转换的例子 * 总结:将字符串转变为字符数组 :public char[] toCharArray() * 直接将一个字符数组变成一个字符串 public String (char[] value) 这个是构造函数啊,可以直接new 并为属性赋值啊. */ public class StringDemo2 { public static void main(String[] args) { String s = "hellow

Golang十六进制字符串和byte数组互转

Golang十六进制字符串和byte数组互转 需求 Golang十六进制字符串和byte数组互相转换,使用"encoding/hex"包 实现Demo package main import ( "encoding/hex" "fmt" ) func main() { str := "ff68b4ff" b, _ := hex.DecodeString(str) encodedStr := hex.EncodeToString

Java 带分隔字符串、字符串数组和 ArrayList&lt;String&gt; 之间的转换

太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS.Android.Html5.Arduino.pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作. 一.先来认识一下标题说的这三件东西,也许描述的不清楚,但有了下面的例子,就不会有歧义了 1.带分隔字符串是这样的: String seperate