0

I read from the documentation about how uri can provide more efficient way of creating url but I am confused as of what's the difference between the following 1, 2 and 3 method?

1)Build url using Uri.Builder. Example:

Uri.Builder.scheme("https")
            .authority("abc.example.com")
            .appendPath("search")
            .appendQueryParameter("id", "123")
            .appendQueryParameter("name", "dummyText")
            .build();

2) using Uri.parse. Example:

Uri.parse("https://abc.example.com/")
            .buildUpon()
            .path("search")
            .appendQueryParameter("id", "123")
            .appendQueryParameter("name", "dummyText")
            .build();

3) concatenating Strings with similar parameters above.

unacorn
  • 827
  • 10
  • 27

1 Answers1

0

The 1st & 2nd are quite similar. Uri.Builder is nested static class ofUri. Also Uri.buildUpon method returns Uri.Builder instance. The only difference is that the former one is more structured and developer-friendly as you don't need to care about : & /. For your third query, you should look at this post uri string difference stackoverflow.

Brijesh Kumar
  • 1,685
  • 2
  • 17
  • 28