Javaのサブストリング()メソッド
サブストリング()メソッドは文字列の部分文字列を返します。
文法
public String substring(int beginIndex) 或 public String substring(int beginIndex, int endIndex)
パラメータ
beginIndexの- (含む)から始まるインデックス。
endIndexに-終了インデックス(含まれていません)。
戻り値
サブストリング。
例
public class Test { public static void main(String args[]) { String Str = new String("www.w3big.com"); System.out.print("返回值 :" ); System.out.println(Str.substring(4) ); System.out.print("返回值 :" ); System.out.println(Str.substring(4, 10) ); } }
上記プログラムの実行結果:
返回值 :w3big.com 返回值 :w3big