Javaの例 - 文字列の最後の出現を探します
我々の文字列関数strOrig.lastIndexOf(Stringname)はstrOrig Stringname中のサブストリングの位置を特定するには、次の例が表示されます。
次のようにコードの例は次のとおりです。
//SearchlastString.java 文件 public class SearchlastString { public static void main(String[] args) { String strOrig = "Hello world ,Hello Reader"; int lastIndex = strOrig.lastIndexOf("Hello"); if(lastIndex == - 1){ System.out.println("Hello not found"); }else{ System.out.println("Last occurrence of Hello is at index "+ lastIndex); } } }
出力は、上記のコード例です:
Last occurrence of Hello is at index 13