StringMethod


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);
 }
}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值