0
0

More than 3 years have passed since last update.

【Java】 文字列の一部を切り出すsubstringの使い方

Last updated at Posted at 2020-10-18

開始位置を指定する場合

String.substring(int beginIndex)
public class Main {

    public static void main(String[] args) {
        String sports = "soccer,baseball,basketball";

        System.out.println(sports.substring(7));
    }

}

実行結果

baseball,basketball

開始、終了位置を指定する場合

String.substring(int beginIndex, int endIndex)
public class Main {

    public static void main(String[] args) {
        String sports = "soccer,baseball,basketball";

        System.out.println(sports.substring(7, 15));
    }

}

実行結果

baseball

参照

Java(tm) Platform, Standard Edition 8 API仕様

0
0
0

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
0