A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 范予帅 中级黑马   /  2015-4-17 23:22  /  348 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  • //熟悉String类的常用方法
  • class StringMethodDemo
  • {
  •         public static void method_get(String str)//获取
  •         {
  •                 sop(str.charAt(4));
  •                 sop(str.indexOf('a'));
  •                 sop(str.indexOf('a',4));
  •                 sop(str.indexOf("ac",8));
  •                 sop(str.length());
  •                 sop(str.lastIndexOf('a'));//反向索引
  •         }
  •         public static void method_judge(String str)//判断:通常用来判断文件名
  •         {
  •                 sop(str.contains("ac"));
  •                 sop(str.isEmpty());
  •                 sop(str.startsWith("ac"));
  •                 sop(str.endsWith("ce"));
  •                 sop(str.substring(3));
  •                 sop(str.substring(3,8));
  •         }
  •         public static void method_trans(String str)//转换,
  •         {        sop(str.trim());
  •                 sop(str.toUpperCase());
  •                 sop(str.toLowerCase)
  •                 char[] c=str.toCharArray();
  •                 for (int x=0;x<c.length ;x++ )
  •                 {
  •                         sop(c[x]);
  •                 }
  •                 String s =new String(c);
  •                 sop("s="+s);
  •                 sop(str.replace('a','b'));
  •                 String[] b=str.split(" ");
  •                 for (int x=0;x<b.length ;x++ )
  •                 {
  •                         sop(b[x]);
  •                 }
  •         }
  •         public static void sop(Object obj)
  •         {
  •                 System.out.println(obj);
  •         }
  •         public static void main(String[] args)
  •         {
  •                 String str="   ac ac ac acbcece  ";
  •                 method_get(str);
  •                 method_judge(str);
  •                 method_trans(str);
  •         }
  • }


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马