public class StringMethod {
public static void main(String[] args)throws Exception
{
StringMethod toUpperCase = new StringMethod();
toUpperCase.a();
String str1="hello";
String str2="world";
String str3="helloworld";
String str4=str1+str2;
System.out.println(str3==str4);
str4=(str1+str2).intern();//如果pool中包含这个字符串,就从池中返回该字符串;否则原String会被加入到pool中并返回这个String对象的引用
System.out.println(str3==str4);
System.out.println("str1是否等同于hello:"+str1.equals("hello"));
//System.out.println("分解字符串"+Integer.parseInt(str1));
String str="waht is your name?";
System.out.println("字符串的长度为:"+str.length());
System.out.println("大写是:"+str.toUpperCase());
System.out.println("小写是:"+str.toLowerCase());
System.out.println("替换name"+str.replace("name","newname"));
//返回指定位置后的子字符串,提取第5个字符之后的
System.out.println("提取"+str.substring(5));
//返回索引处是0的字符,从0开始计算
System.out.println("在0位置出的字符是:"+str.charAt(0));
System.out.println("在位置4出现的字符是:"+str.charAt(4));//索引是4的位置是一个空格.
byte[] strb=str.getBytes();
int j=str.indexOf('a');
System.out.println("字符a第一次出现的索引:"+j);
System.out.println("字符a最后一次在该字符串出现的索引:"+str.lastIndexOf('a'));
System.out.println("转换为字符树组");
char[] strch=str.toCharArray();
for(int k=0;k<strch.length;k++)
{
System.out.print(strch[k]);
}
System.out.println();
for(int i=1;i<6;i++)
{
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
public void a()
{
int ii = 5;
// String str = "";
// str = String.valueOf(ii);
System.out.println(ii);
}
}