public String replace(char oldChar, char newChar ) ------将旧字符串替换成新的字符串
public String[] split(String str) ------根据str作拆分
代码详情:
public class Demo05 {
public static void main(String[] args) {
String content="java是世界上最好的java编程语言,java真香";
//10.replace(char old char new);用新的字符/字符串替换旧的字符/字符串
System.out.println(content.replace("java","php"));
//11.split();对字符串进行拆分
String say="java is the best programing language,java xiang";
String[] arr=say.split("[ ,]+");
System.out.println(arr.length );
for (String string:arr) {
System.out.println(string);
}
System.out.println("=======================");
//补充两个方法equals、compareTo();
String s1="hello";
String s2="HELLO";
System.out.println(s1.equals(s2));
//equalsIgnoreCase 忽略大小写的比较
System.out.println(s1.equalsIgnoreCase(s2));
//compareTo();比较大小:比较的是两个字符在编码表里面的位置
String s3="abc";//a:97
String s4="xyz";//x:120
System.out.println(s3.compareTo(s4));
//此时比较的是长度,3-6=-3;输出结果为-3
String s5="abc";
String s6="abcxyz";
System.out.println(s5.compareTo(s6));
}
}
标签:常用,java,String,System,char,println,方法,out From: https://www.cnblogs.com/anonymity12/p/18214871