/*
String类中
*/
class StringMethodDemo
{
public static void method_7()
{
String s=" Hello Java ";
sop(s.toLowerCase());
sop(s.toUpperCase());
sop(s.trim());
String s1="abc";
String s2="aaa";
sop(s1.compareTo(s2));
}
public static void method_sub()
{
String s="abcdef";
sop(s.substring(2));//从指定位置开始到结尾
sop(s.substring(2,4));//包含头,不含结尾 s.substring(0,s.length());
}
public static void method_split()
{
String s="zhangsa,lisi,wangwu";
String[] arr=s.split(",");
for (int x=0;x<arr.length ;x++ )
{
sop(arr[x]);
}
}
public static void method_replace()
{
String s="hello java";
//String s1=s.replace('a','n');//如果要替换的字符不存在,返回原串
String s1=s.replace("java","word");
sop("s="+s);
sop("s1="+s1);
}
public static void method_trans()
{
char[] arr={'a','b','c','d','e','f'};
String s=new String(arr,1,3);
sop("s="+s);
String s1="zxcvbnm";
char[] chs=s1.toCharArray();
for (int x=0;x<chs.length ;x++ )
{
sop("chs="+chs[x]);
}
}
public static void method_is()
{
String str="ArrayDemo.java";
//判断文件名称是否Array单词开头
sop(str.startsWith("Array"));
//判断文件名称是否.java单词结尾
sop(str.endsWith(".java"));
//判断文件名称是否包含Demo单词
sop(str.contains("Demo"));
}
public static void method_get()
{
String str="abcdeakpf";
//长度
sop(str.length());
//根据索引获取字符
sop(str.charAt(4));//当访问到字符串不存在的角标会发生StringIndexOutOfBoundsException
//根据字符获取索引
sop(str.indexOf('m',3));//如果没有找到,返回-1
//反向索引一个字符
sop(str.lastIndexOf("a"));
}
public static void main(String[] args)
{
method_7();
//method_sub();
//method_split();
//method_replace();
//method_trans();
//method_is();
//method_get();
/*String s1="abc";
String s2=new String("abc");
String s3="abc";
System.out.println(s1==s2);
System.out.println(s1==s3);*/
}
public static void sop(Object obj)
{
System.out.println(obj);
}
}
String类中
*/
class StringMethodDemo
{
public static void method_7()
{
String s=" Hello Java ";
sop(s.toLowerCase());
sop(s.toUpperCase());
sop(s.trim());
String s1="abc";
String s2="aaa";
sop(s1.compareTo(s2));
}
public static void method_sub()
{
String s="abcdef";
sop(s.substring(2));//从指定位置开始到结尾
sop(s.substring(2,4));//包含头,不含结尾 s.substring(0,s.length());
}
public static void method_split()
{
String s="zhangsa,lisi,wangwu";
String[] arr=s.split(",");
for (int x=0;x<arr.length ;x++ )
{
sop(arr[x]);
}
}
public static void method_replace()
{
String s="hello java";
//String s1=s.replace('a','n');//如果要替换的字符不存在,返回原串
String s1=s.replace("java","word");
sop("s="+s);
sop("s1="+s1);
}
public static void method_trans()
{
char[] arr={'a','b','c','d','e','f'};
String s=new String(arr,1,3);
sop("s="+s);
String s1="zxcvbnm";
char[] chs=s1.toCharArray();
for (int x=0;x<chs.length ;x++ )
{
sop("chs="+chs[x]);
}
}
public static void method_is()
{
String str="ArrayDemo.java";
//判断文件名称是否Array单词开头
sop(str.startsWith("Array"));
//判断文件名称是否.java单词结尾
sop(str.endsWith(".java"));
//判断文件名称是否包含Demo单词
sop(str.contains("Demo"));
}
public static void method_get()
{
String str="abcdeakpf";
//长度
sop(str.length());
//根据索引获取字符
sop(str.charAt(4));//当访问到字符串不存在的角标会发生StringIndexOutOfBoundsException
//根据字符获取索引
sop(str.indexOf('m',3));//如果没有找到,返回-1
//反向索引一个字符
sop(str.lastIndexOf("a"));
}
public static void main(String[] args)
{
method_7();
//method_sub();
//method_split();
//method_replace();
//method_trans();
//method_is();
//method_get();
/*String s1="abc";
String s2=new String("abc");
String s3="abc";
System.out.println(s1==s2);
System.out.println(s1==s3);*/
}
public static void sop(Object obj)
{
System.out.println(obj);
}
}