How to get the last part of a URL after the last slash (/) in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String url = "http://www.website.com/abc/xyz";

        String s = url.substring(url.lastIndexOf('/') + 1, url.length());
        
        System.out.println(s);
    }
}


/*
run:

xyz

*/

 



answered Feb 19, 2020 by avibootz

Related questions

1 answer 168 views
1 answer 230 views
2 answers 325 views
2 answers 266 views
3 answers 902 views
1 answer 225 views
3 answers 360 views
...