Problem with Parsing path

Hello, I am having a couple of problems with parsing path.
My first problem is with splitting the URI, lets say i have the URI scheme://host/path/path2. If i say

String rest = containuri.split("/")[1];

it would split the URI in 5 but when in reality i just want to split at the second last /. So I’m not sure how to get around that.
My second problem:
Lets say that i managed to split the URI correctly and i got the path. Well a correct path would look like “/path/path2” but if i split at / it would remove the first one.
Thank you in advance

You could use String::indexOf(int) and String::indexOf(int,int) in combination with String::substring(int,int), though I would highly recommend using regular expressions (“RegEx”), see Pattern and Matcher::matches() as they make it easier to validate a string especially for a more complicated grammar.

Also note that the code you provided will result in an ArrayIndexOutOfBoundsException if the URI is invalid, like