简体   繁体   中英

To create URL - what's the difference between using uri.parse / uri.builder / concatenate string?

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.

The 1st & 2nd are quite similar. Uri.Builder is nested static class of Uri . 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM