java – Strange behavior of the split method

Question:

I am trying to split a string into an array of substrings – found the split method. But whatever the string is initially equal to, an empty array is always returned.

The code:

String testSplit = "blog.hashcode.ru"; 
String[] result = testSplit.split("."); 
// по идее размер массива должен быть равен трём
System.out.println(result.length());

Result:

0

Answer:

This is because split works with regexp

"blog.hashcode.ru".split(Pattern.quote("."))
Scroll to Top