Use lastIndexOf , for example:
String url = "localhost:8080/myproject/actor/take/154/"; int start = url.lastIndexOf('/', url.length()-2); if (start != -1) { String s = url.substring(start+1, url.length()-1); int n = Integer.parseInt(s); System.out.println(n); }
This is the main idea. You will need to do some error checking (for example, if the number is not found at the end of the URL), but it will work fine.
source share