String的常用操作

    xiaoxiao2021-12-10  12

    1、String可以和char数组、byte数组互换

    //字符串转换为字符数组或者字节数组 String s = "abc"; char[] charArr = s.toCharArray(); byte[] byteArr = s.getBytes(); //字符数组或者字节数组转换成字符串 String s1 = new String(charArr); String s3 = String.valueOf(charArr); String s2 = new String(byteArr);

    2、字符串倒序

    String s = "abc"; StringBuilder sb = new StringBuilder(s); sb = sb.reverse(); System.out.println(sb); //将StringBuilder转换成String String s4= sb.toString(); String s5 = String.valueOf(sb);
    转载请注明原文地址: https://ju.6miu.com/read-700264.html

    最新回复(0)