Java-String转Byte数组

package com.StringTest;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class StringToByte {

    public static void main(String[] args) {
        String str1 = "abc123";
        //String转byte[]
        byte[] bytes = str1.getBytes(StandardCharsets.UTF_8);
        System.out.println(Arrays.toString(bytes));

        //byte[]转String
        String s = new String(bytes);
        System.out.println(s);
    }

}

你可能感兴趣的:(Java,java,开发语言,后端)