tag:blogger.com,1999:blog-9905395.post5694877039402274675..comments2023-06-13T02:09:57.338-06:00Comments on David Rupp's Blog: Java 1, Intuition 0David Rupphttp://www.blogger.com/profile/16410820024654313029noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-9905395.post-13101959845282415522007-11-04T09:51:00.000-07:002007-11-04T09:51:00.000-07:00At least there is a split() method. Where the hec...At least there is a split() method. Where the heck is join()? Why arrays and Lists cannot join their elements together is a question I've spent too much time considering. For that matter, why can't a List sort itself?Davidhttps://www.blogger.com/profile/02362609695105488721noreply@blogger.comtag:blogger.com,1999:blog-9905395.post-11416518849604171212007-10-06T12:45:00.000-06:002007-10-06T12:45:00.000-06:00Thanks, William. I agree that your explanation mak...Thanks, William. I agree that your explanation makes sense; thanks for the thoughtful and reasonable response. :-)David Rupphttps://www.blogger.com/profile/16410820024654313029noreply@blogger.comtag:blogger.com,1999:blog-9905395.post-81148588716882889272007-10-05T10:23:00.000-06:002007-10-05T10:23:00.000-06:00To be honest, it makes sense to me. The result yo...To be honest, it makes sense to me. The result you got follows the same behavior as if you had written:<BR/><BR/>"abc".split("\\s");<BR/><BR/>In this case, the returned String[] contains one element, the original string "abc"; in your case, the original string happened to be empty.<BR/><BR/>I can understand the confusion if one were to assume that the "split" method unconditionally resulted in an array of substrings that were, in fact, split from the original -- for the same reasons you list: what does it mean to split the empty string?<BR/><BR/>However, if you think of split's behavior as, "Split the given string around any token matching a given pattern, if such a token is found," then the observed (and documented) behavior makes sense. I don't find that too unintuitive.Unknownhttps://www.blogger.com/profile/10619714273274185474noreply@blogger.com