//创建对象格式:类名 对象名 = new 类名([参数]);
String s = new String("嘻嘻嘻");
String s2 = "嘿嘿嘿";
System.out.println("s2:"+s2);
System.out.println("s:"+s);
String str = "今天是个好日子嘿1嘿2嘿3";
//返回指定索引位置的字符(索引位置从0开始)
char c = str.charAt(3);
System.out.println("c:"+c);
// t1大时返回正数、t2大时返回负数、相同时返回0
String t1 = "ab丹";
String t2 = "ab曹";
System.out.println(t1.compareTo(t2));
// System.out.println((int)'丹');
// 将指定字符串连接到此字符串的结尾
// t2 = t2+"刘志鹏";
t2 = t2.concat("斌斌");
System.out.println(t2);
s = "今天是嘿个好日子,嘿一起去泡脚呀,嘿嘿";
//在字符串中查询第一次出现的字符索引位置
int i = s.indexOf("嘿个");
System.out.println(i);
s = "";
//求出字符串长度(字符个数)
System.out.println(s.length());
// 只有当字符串长度为0的时候才返回true
boolean b = s.isEmpty();
System.out.println(b);
s = "今天天个是个今天嘿嘿嘿今天";
//返回字符串中 指定的字符最后一次出现的索引位置
System.out.println(s.lastIndexOf("天"));
//用指定字符串替换字符串中的指定字符(不管出现几次全部替换)
s = s.replace("今", "明日");
System.out.println(s);
s = "明硕,昱程,昊,俊萱大佐";
//拆分:根据指定个字符格式(正则表达式)进行拆分
String[] ss = s.split(",");//创建字符串数组接收拆分后的值
//遍历数组
for (int j = 0; j < ss.length; j++) {
System.out.println(ss[j]);
}
//从指定位置开始截取到最后
s = s.substring(2);
System.out.println(s);
s = "abcdefg";
//从指定开始位置截取到 指定的结束位置(不包括结束位置的元素)
s = s.substring(2, 6);
System.out.println(s);
//把字符串转换为char类型的数组
char[] cs = s.toCharArray();
for (int j = 0; j < cs.length; j++) {
System.out.println(cs[j]);
}
//大写转小写toLowerCase()
String ww = "WWWWWW";
System.out.println(ww.toLowerCase());
//小写转大写toUpperCase()
ww = "asasfas";
System.out.println(ww.toUpperCase() );
s = " a b ";
System.out.println(s);
//去除前后的空格,不管中间的
System.out.println(s.trim());