Java – Common Gotchas [closed]

"a,b,c,d,,,".split(",").length

returns 4, not 7 as you might (and I certainly did) expect. split ignores all trailing empty Strings returned. That means:

",,,a,b,c,d".split(",").length

returns 7! To get what I would think of as the “least astonishing” behaviour, you need to do something quite astonishing:

"a,b,c,d,,,".split(",",-1).length

to get 7.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)