集册 Java实例教程 使用indexOf搜索字符串

使用indexOf搜索字符串

欢马劈雪     最近更新时间:2020-01-02 10:19:05

425
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用indexOf搜索字符串


public class Main {

 /*时 代      J a v a   公   众 号 - nowjava.com 提供*/

  public static void main(String[] args) {

    //declare a String object

    String strOrig = "Hello world Hello World";

    int intIndex = strOrig.indexOf("Hello");

   

    if(intIndex == - 1){

      System.out.println("Hello not found");

    }else{

      System.out.println("Found Hello at index " + intIndex);      

    }

   

    int positionIndex = strOrig.indexOf("Hello",11);

    System.out.println("Index of Hello after 11 is " + positionIndex);

   //from 时 代 J a v a

    int
展开阅读全文