java講座
sample1 substring
sample2 equalsIgnoreCase
sample3 startsWith endsWith
sample4 indexOf lastIndexOf
sample5 split
sample6 format
top
blog
sample2 equalsIgnoreCase
sample3 startsWith endsWith
sample4 indexOf lastIndexOf
sample5 split
sample6 format
top
blog
sample4 JAVA講座 文字列関数 indexOf lastIndexOf
ここではJAVAのサンプルプログラムを紹介しています。文字列関数 indexOf は文字列が引数の文字列が含まれている場所をintで返します。 文字列関数 lastIndeOf は文字列の後ろから検索します。
int i = str.indexOf("cde");
としてstrの"cde"で始まる場所を検索します。先頭は0です。文字列が含まれない場合は-1を返します。
str.lastIndexOf("cde");
としてstrの後ろから"cde"を探します。
結果は
2
-1
7
となります。
-1
7