如何使用java.lang.String.contains()方法

实例

package com.yiibai;

import java.lang.*;

public class StringDemo {

  public static void main(String[] args) {
  
    String str1 = "tutorials point", str2 = "http://";

    CharSequence cs1 = "int";
    
    // string contains the specified sequence of char values
    boolean retval = str1.contains(cs1);
    System.out.println("Method returns : " + retval);
    
    // string does not contain the specified sequence of char value
    retval = str2.contains("_");   
    System.out.println("Methods returns: " + retval);
  }
}
让我们来编译和运行上面的程序,这将产生以下结果:

Method returns : true
Methods returns: false

posted on 2015-12-31 21:06  tengke  阅读(2905)  评论(0编辑  收藏  举报