Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...