String incomingNumbers[ ] = writtenNumber.split("\\-");
プログラムは、32や5などの自然言語番号を受け入れます。
では、5つ入力すると、incomingNumbers配列には何が入りますか?
元の値を保持するサイズ1の配列を取得します。
Input Output
----- ------
thirty-two {"thirty", "two"}
five {"five"}
これは、次のプログラムで実際に動作していることがわかります。
class Test {
static void checkResult (String input) {
String [] arr = input.split ("\\-");
System.out.println ("Input : '" + input + "'");
System.out.println (" Size: " + arr.length);
for (int i = 0; i < arr.length; i++)
System.out.println (" Val : '" + arr[i] + "'");
System.out.println();
}
public static void main(String[] args) {
checkResult ("thirty-two");
checkResult ("five");
}
}
出力:
Input : 'thirty-two'
Size: 2
Val : 'thirty'
Val : 'two'
Input : 'five'
Size: 1
Val : 'five'