首页 > 其他 > 详细

String常用方法

时间:2016-09-07 20:39:44      阅读:165      评论:0      收藏:0      [点我收藏+]
public class first
{public static void main(String args[]){
    String asd = "helloworld";
    String asf = "hello world love";
    System.out.println(asd.contains("hello"));//判断“hello”是否存在
    System.out.println(asd.indexOf("d",5));//从第5开始查找 d 的位置 返回他的索引找不到返回-1
    System.out.println(asd.lastIndexOf("h",1));
     System.out.println(asd.startsWith("ll",1));//从索引1开始查找 判断是否以ll开头
     System.out.println(asd.replaceAll("o","-"));//把o替换成-
    System.out.println(asd.substring(1,5));
   String it [] = asf.split("\\ ");//拆分操作
   for (int x=0;x<it.length ;x++ )
   { System.out.println(it[x]);
   }
    }
}

 

String常用方法

原文:http://www.cnblogs.com/shuaiqiyang/p/5850779.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!