LoginSignup
0

More than 3 years have passed since last update.

Java 部分文字列

Last updated at Posted at 2020-09-13

【Java 部分文字列】

業務でよく使用する Javaの部分文字列のメモです。

部分文字列 substring

substringメソッドの第一引数に抜き出し開始の位置(beginIndex)、第二引数に抜き出し終了の位置(endIndex)を指定する。

部分文字列は、beginIndexから始まり、endIndex-1 までを表す。

・substringの例

"サンプル文字".substring(beginindex, endindex-1);

beginindexは、0番目から数え始める。
配列の添え字の数え方と同じ。

・文字の長さは、endIndex - beginIndex

"サンプル文字".substring(0, 4);

//出力結果:サンプル

この場合だと、文字の長さ 4-0=4
なので、4文字が部分文字列として表示される。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0