/*
String类中方法的测试
‘abc’
*/
public class StringTestDemo
{
public static void sop(Object obj)
{
System.out.println(obj);
}
public static void get_String(String str)
{
//获取str的hashCode()值
sop(str.hashCode());
//返回指定索引处的 char 值
sop(str.charAt(4));
// 返回指定字符在此字符串中第一次出现处的索引
sop(str.indexOf('a'));
//返回 参数的字符串表示形式
sop(str.valueOf(str));
//valueOf(char[] data, int offset,int count)数组参数的特定子数组的字符串表示形式
//String[] b = str.valueOf(char[] a,5,10);
//sop(b);
//substring(int beginIndex,int endIndex):返回一个新的字符串,它是此字符串的一个子字符串
sop(str.substring(9));//返回下标为9之后的一个字串。
sop(str.substring(1,9));//返回从1~9的子串。
//subSequence(int beginIndex,int endIndex):返回一个新的字符序列,它是此序列的一个子序列。
String b =(String)str.subSequence(5,9);//返回从5~9的子串
sop(b);
//toUpperCase():默认语言环境的规则将此 String 中的所有字符都转换为大写
//sop(str.toUpperCase(str));问题:无法通过方法调用转换将实际参数String转换为Locale。
}
public static void main(String[] args)
{
String str = "abcdefghijklmnopqrstuvwxyz";
//String a = (String)str.clone();没有成功
//sop(a);
get_String(str);
}
}