LoginSignup
1
0

More than 3 years have passed since last update.

【Java】splitメソッド

Posted at

splitメソッドは、
Stringで定義した区切り文字列を分割することで、
文字列の配列に分ける。
(文字列を指定された正規表現に一致する位置で分割する)

サンプルコード

String str = "りんご,レモン,すいか,ブドウ"

String[] fruit = str.split(",", 0);

/**
*結果:
*fruit[0] = "りんご"
*fruit[1] = "レモン"
*fruit[2] = "すいか"
*fruit[3] = "ブドウ"
*/

最後の0のところは、
分割する回数を指す。
負の値を指定すると制限なし。

1
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
1
0