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://
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.
This article is contributed by Pranav . If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Check if email address valid or not in Java
- Check if a given string is a valid number (Integer or Floating Point) in Java
- Program to check valid mobile number
- Valid variants of main() in Java
- Check if a value is present in an Array in Java
- Check for string rotation in Java
- How to check if a key exists in a HashMap in Java
- Check if a File is hidden in Java
- Check if a string contains only alphabets in Java using Regex
- Check whether two Strings are Anagram of each other using HashMap in Java
- Check if a String starts with any of the given prefixes in Java
- Check if a string contains only alphabets in Java using ASCII values
- Check if a string contains only alphabets in Java using Lambda expression
- Java program to check palindrome (using library methods)
- Quick ways to check for Prime and find next Prime in Java