与转换相关的方法
public char[] toCharArray():将当前字符串拆分为字符数组作为返回值
public byte[] getBytes():获得当前字符串底层的字节数组
public String replace(CharSequence oldString ,CharSequence newString)
将所有出现的老字符串替换为新的字符串,返回替换之后的结果新字符串
备注:CharSequence意思就是说可以接受字符串类型
public class Demo06StringConvert {
public static void main(String[] args) {
char[] chars = "Hello".toCharArray();
System.out.println(chars[0]);//H
System.out.println(chars.length);//5
System.out.println("===================");
//转换成为字节数组
byte[] bytes = "abc".getBytes();
for (int i = 0; i < bytes.length; i++) {
System.out.println(bytes[i]);
}
System.out.println("===================");
//字符串内容的替换
String str = "How do you do?";
String str1 = str.replace("o","*");
System.out.println(str);
System.out.println(str1);
}
}