字符串,字节,字符相互转换

让人想犯罪 __ 提交于 2019-12-17 04:40:03
public class TestClass {
    public static void main(String[] args) {
        String a = "cccc";
        //字符串转字节
        byte[] bytes = a.getBytes();
        for (byte aByte : bytes) {
            System.out.println(aByte);
        }
        //字符串转char
        char[] chars = a.toCharArray();
        for (char aChar : chars) {
            System.out.println(aChar);
        }

        //字节转字符串
        byte[] bytes1 = {99, 99, 99, 99};
        String s = new String(bytes1);
        System.out.println(s);
        //字符转字符串
        char[]chars1={'c','c','c','c'};
        String s1 = new String(chars1);
        System.out.println(s1);

    }
}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!