VOOZH about

URL: https://www.geeksforgeeks.org/java/check-if-url-is-valid-or-not-in-java/

⇱ Check if URL is valid or not in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Check if URL is valid or not in Java

Last Updated : 30 May, 2018
Given a URL as string, we need to find if the given URL is valid or not.
Input : str = "https://www.geeksforgeeks.org/"
Output : Yes


Input : str = "https:// www.geeksforgeeks.org/"
Output : No
Note that there is a space after https://
Using java.net.url We can use java.net.url class to validate a URL. The idea is to create a URL object from the specified String representation. If we do not get exception while creating the object, we return true. Else we return false. Output:
Yes
No
Comment
Article Tags: