「Java入門」 java.lang.String.lastIndexOf(String str)のサンプル

Javaコード

package itstudy;

public class SearchlastString {

public static void main(String[] args) {
String strOrg = “Hello world ,Hello Reader,Hello Tony";
int lastIndex = strOrg.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 26

Java

Posted by arkgame