Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (800 points)

How can I convert a String to a Uri in Java (Android)? i.e.:

String myUrl = "http://stackoverflow.com";

myUri = ???

1 Answer

0 votes
by (13.2k points)
  1. Use the parse method of uri, which is a static method and easy one-liner.

Uri myUri = Uri.parse("http://stackoverflow.com")

OR

  1. Directly use java.net package

String myUrl = "http://stackoverflow.com";

URI myURI = new URI(myUrl);

Related questions

0 votes
1 answer
asked Sep 15, 2019 in Java by Suresh (3.4k points)
0 votes
1 answer
asked Nov 19, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
asked Jul 26, 2019 in Java by Shubham (3.9k points)

Browse Categories

...