How to parse or split URL Address in Java? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How to parse or split URL Address in Java? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

If I have url address.

https://graph.facebook.com/me/home?limit=25&since=1374196005

Can I get(or split) parameters (avoiding hard coding)?

Like this

https /// graph.facebook.com /// me/home /// {limit=25, sincse=1374196005}

Answer

Use Android’s Uri class. http://developer.android.com/reference/android/net/Uri.html

Uri uri = Uri.parse("https://graph.facebook.com/me/home?limit=25&since=1374196005");
String protocol = uri.getScheme();
String server = uri.getAuthority();
String path = uri.getPath();
Set<String> args = uri.getQueryParameterNames();
String limit = uri.getQueryParameter("limit");
We are here to answer your question about How to parse or split URL Address in Java? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji