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 151 views
1 answer 213 views
2 answers 303 views
2 answers 241 views
3 answers 823 views
1 answer 209 views
3 answers 329 views
...