操作字符串

class Stringtest
{
 public static void main(String[] args)
 {   // &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
     // String
  // 截取
  // .charAt
  char ch;
  ch="abc".charAt(2);
  System.out.println(ch);

        // .getChars
  String s="This is a demo of the getChars method. ";
  int start=10;
  int end=14;
  char buf[]=new char[end-start];
  s.getChars(start,end,buf,0);
  System.out.println(buf);

  // .getBytes  --用法不清楚
        System.out.println(s.getBytes());

  // .toCharArray -- 把字符串转成字符数组
  char tochararray[]=s.toCharArray();
  System.out.println(tochararray[3]);

  // 比较
  // .equals
  // .equalsIgnoreCase 忽略大小写
  // .regionMatches  比较指定区间的字符串,重载形式可以忽略大小写
  // .startsWith     是否以指定的字符串开始
  // .endsWith       是否以指定的字符串结束
  // .compareTo     
  // .compareToIgnoreCase

  // 搜索
  // .indexOf  首次出现
  // .lastIndesOf 最后一次出现

  // 修改
  // .substring   截取
  // .concat      连接
  // .replace     替代
  // .trim        去空格

  // .valueOf  可以把每一种类型都转换成字符串

  // 改变大小写
  // .toLowerCase
  // .toUpperCase

  // &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  // StringBuffer
  // .length
  // .capacity
  // .ensureCapacity  设置缓冲区大小
  // .setLength   设置缓冲区大小
  // .charAt
  // .setCharAt
  // .setLength
  // .getChars 把子字符串赋值给数组
  // .append
  // .insert
  // .reverse 返回被调用对象的翻转对象
  // .delete       StringBuffer自增加的
  // .deleteCharAt StringBuffer自增加的
  // .replace      StringBuffer自增加的
  // .substring

 }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值