Pythonで文字列を分割すると、隣接するスペース区切り文字がマージされます。
>>> str = "hi there"
>>> str.split()
['hi', 'there']
Javaでは、区切り文字はマージされません。
$ cat Split.java
class Split {
public static void main(String args[]) {
String str = "hi there";
String result = "";
for (String tok : str.split(" "))
result += tok + ",";
System.out.println(result);
}
}
$ javac Split.java ; java Split
hi,,,,,,,,,,,,,,there,
JavaでPythonスペース分割セマンティクスを取得する簡単な方法はありますか?