Java Utililty Methods URL Value Check

List of utility methods to do URL Value Check

Description

The list of methods to do URL Value Check are organized into topic(s).

Method

booleanisValidURL(String url)
Checks if the URL is valid or not.
try {
    URL urlObj = new URL(url);
    String host = urlObj.getHost();
    assert !host.isEmpty();
    assert host.contains(".");
} catch (MalformedURLException e) {
    return false;
} catch (AssertionError e) {
...
booleanisValidURL(String url)
is Valid URL
try {
    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
    conn.setConnectTimeout(3000);
    conn.connect();
    conn.disconnect();
    return conn.getResponseCode() >= 200 && conn.getResponseCode() < 300;
} catch (Exception e) {
    e.printStackTrace();
...
booleanisValidURL(String url)
is Valid URL
if (url.length() < 10)
    return false;
url = url.trim();
if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("ftp://")) {
    String host = null;
    try {
        host = getHostName(url);
    } catch (MalformedURLException e) {
...
booleanisValidUrl(String url)
Check whether provided url string is a valid java java.net.URL
try {
    if (Strings.isNullOrEmpty(url)) {
        return false;
    new URL(url);
    return true;
} catch (MalformedURLException e) {
    return false;
...
booleanisValidURL(String URL_String)
Opens up a connection with the given URL and returns true if the response code is 200 (success)
try {
    URL url = new URL(URL_String);
    url.toURI();
} catch (MalformedURLException e) {
    return false;
} catch (URISyntaxException e) {
    return false;
return true;
booleanisValidURL(String urlStr)
is Valid URL
return parseURI(urlStr) != null;
booleanisValidURL(String urlStr)
Checks whether the given string is a valid URL.
if (urlStr == null) {
    return false;
try {
    URI uri = new URI(urlStr);
    if (uri.getScheme() == null) {
        return false;
    return uri.getScheme().equals("http") || uri.getScheme().equals("https");
} catch (URISyntaxException e) {
    return false;
URLisValidURL(String urlString)
is Valid URL
try {
    return new URL(urlString);
} catch (Exception e) {
    return null;
booleanisValidUrl(URI uri)
is Valid Url
try {
    uri.toURL();
} catch (MalformedURLException | IllegalArgumentException e) {
    return false;
return true;
booleanisValidURL(URL url)
is Valid URL
try {
    if (isHttpUrl(url.toString())) {
        URLConnection connection = url.openConnection();
        if (connection instanceof HttpURLConnection) {
            HttpURLConnection httpConnection = (HttpURLConnection) connection;
            httpConnection.setConnectTimeout(1000);
            httpConnection.connect();
            int response = httpConnection.getResponseCode();
...