public static void main(String[] args) {
stuName();
xiaoMi();
showChar();
printIsContain();
xiaoMii();
xiaoMia();
xiaoMib();
xiaoMic();
xiaoMid();
xiaoMie();
}
public static void stuName() {
String a = "小明";
int b = 17;
float c = 92.5f;
String d = a + "的年龄是" + b + ',' + "成绩是" + c;
System.out.println(d);
}
public static void xiaoMi() {
String l = "http://www.baidu.com";
String k = "字符长度是";
int xiaoMi = l.length();
System.out.println(k + xiaoMi);
}
public static void showChar() {
String str = "123456789";
char one = str.charAt(0);
char two = str.charAt(5);
char three = str.charAt(8);
System.out.println(one + " " + two + " " + three + " ");
}
public static void printIsContain() {
String str = "wei_xue_yuan_is_good";
String a = "Warmtel";
String b = "arm";
boolean c = a.contains(b);
String s = c ? "包含" : "不包含";
System.out.println(c);
}
public static void xiaoMii() { // 使用两种方式实现向字符串"欢迎来到java"后追加字符串"世界";
StringBuilder sb = new StringBuilder();
sb.append("欢迎来到java");
sb.append("世界");
System.out.println(sb);
}
public static void xiaoMia() {
StringBuilder sb = new StringBuilder("欢迎来到java");
sb.append("世界");
System.out.println(sb);
}
public static void xiaoMib() { // 向字符串"welme"第2个字符后插入字符串"co",生成新的字符串
// "welcome"
StringBuilder sb = new StringBuilder("welme");
sb.insert(3, "co");
System.out.println(sb);
}
public static void xiaoMic() {// 删除字符串"helloworld"中第5个字符和第7个字符
StringBuilder sb = new StringBuilder("helloworld");
sb.deleteCharAt(4);
sb.deleteCharAt(6);
System.out.println(sb);
}
public static void xiaoMid() {// 从字符串"welcometoscxh"中获取子字符串"come"
StringBuilder sb = new StringBuilder("welcometoscxh");
String a = sb.substring(3, 7);
System.out.println(a);
}
public static void xiaoMie() { // replace()方法,用来替换字符串中所有指定的子串,
StringBuilder sb = new StringBuilder(
"The url of weixueyuan is www.warmtel.com!");
sb.replace(11, 21, "warmtel"); // 例如
// "The url of weixueyuan is www.warmtel.com!"
System.out.println(sb); // 替换weixueyuan 为warmtel.
}
}