public class String_fangfa {
public static void main(String[] args) {
// A:判断功能
// boolean equals(Object obj) 区分大小写
// boolean equalsIgnoreCase(String str) 不区分大小写
// boolean contains(String str)
// boolean startsWith(String str)
// boolean endsWith(String str)
// boolean isEmpty()
String str="JHQheima";
System.out.println(str.equals("JHQheima"));
System.out.println(str.equals("jhqheima"));
System.out.println(str.equalsIgnoreCase("jhqheima"));
System.out.println(str.contains("JHQ"));
System.out.println(str.startsWith("Qhei",2));
System.out.println(str.startsWith("j"));
//System.out.println(str.endsWith("Qhei",5));//没有这个方法
System.out.println(str.endsWith("ma"));
System.out.println(str.isEmpty());
// B:获取功能
// int length()
// char charAt(int index)
// int indexOf(int ch)
// int indexOf(String str)
// int indexOf(int ch,int fromIndex)
// int indexOf(String str,int fromIndex)
// String substring(int start)
// String substring(int start,int end)
String strb="nhnihaoyanihpi";
System.out.println(strb.length());
System.out.println(strb.charAt(3));
System.out.println(strb.indexOf(97));
System.out.println(strb.indexOf("hao"));
System.out.println(strb.indexOf('h',6));
System.out.println(strb.indexOf("ni",5));
// String substring(int start)
// String substring(int start,int end)
//String strb="nhnihaoyanihpi";
System.out.println(strb.substring(3));
System.out.println(strb.substring(6));
System.out.println(strb.substring(3, 7));
// C:转换功能
// byte[] getBytes()
// char[] toCharArray()
// static String copyValueOf(char[] chs)
// static String valueOf(char[] chs)
// static String valueOf(int i)
// String toLowerCase()
// String toUpperCase()
// String concat(String str)
String strC="jiahuaiqing";
byte[] byby=strC.getBytes();
for (int i = 0; i < byby.length; i++) {
System.out.println(byby[i]);
}
char[] chch=strC.toCharArray();
for (int i = 0; i < chch.length; i++) {
System.out.println(chch[i]);
}
//System.out.println(byby);
char[] cha={'c','a','b','黑','马'};
String sss=String.valueOf(cha);
System.out.println(sss);
String xiaoxue=strC.toLowerCase();
System.out.println(xiaoxue);
System.out.println(strC.toUpperCase());
String pingjie=strC.concat("+aaaa");
System.out.println(pingjie);
}
}
===============执行结果如下=========================
true
false
true
true
true
false
true
false
14
i
5
4
11
9
ihaoyanihpi
oyanihpi
ihao
106
105
97
104
117
97
105
113
105
110
103
j
i
a
h
u
a
i
q
i
n
g
cab黑马
jiahuaiqing
JIAHUAIQING
jiahuaiqing+aaaa |
|