user3222372
user3222372

Reputation: 382

Java split generates empty first string

There is path like this /root/folder1/subfolder1/subfolder2. Using split() method it generates empty first element. How can first empty string be avoided ?

Upvotes: 0

Views: 39

Answers (1)

Andreas
Andreas

Reputation: 159086

Strip the leading / before calling split("/").

Use e.g. replaceFirst("^/", "") to do that.

Upvotes: 2

Related Questions