package Demo_1_22_String; public class String_byte { public static void main(String[] args) { String str = "www.baidu.com"; byte [] bytes = str.getBytes(); for (int i = 0; i < bytes.length; i++) { if (bytes[i] == '.') { }else { bytes[i] -= 32;; // 编码表的位置向前移动32位 } } System.out.println(new String(bytes)); System.out.println(new String(bytes,0,5)); //从索引0开始长度为5 } }