首页 > 其他 > 详细

1.12 判断字符串第一次出现的位子 和 字符串是否存在

时间:2017-05-10 00:53:18      阅读:362      评论:0      收藏:0      [点我收藏+]

package Demo;

public class Demo4 {
 public static void main(String[] args) {
  String str = "helloworld";
   /*if(str.indexOf("hello")!=-1){
    System.out.println("位置是:"+str.indexOf("hello"));  // 位置是:0
   
   }else{
    System.out.println(-1); 
   }*/
  
  
  //检查是否存在
  if(str.contains("hello")){
   System.out.println("位置是:"+str.contains("hello"));
  }else{
    System.out.println(-1); // 位置是:true
   }
 }
}

1.12 判断字符串第一次出现的位子 和 字符串是否存在

原文:http://www.cnblogs.com/mengliang/p/6833381.html

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