You can check if location starts with http:// or https:// :
String s = location.trim().toLowerCase(); boolean isWeb = s.startsWith("http://") || s.startsWith("https://");
Or you can use the URI class instead of the URL , the URI does not throw a MalformedURLException as the URL class:
URI u = new URI(location); boolean isWeb = "http".equalsIgnoreCase(u.getScheme()) || "https".equalsIgnoreCase(u.getScheme())
Although new URI() may also throw a URISyntaxException if you use a backslash in a location, for example. The best way is to either use a prefix check (my first sentence), or create a URL and catch MalformedURLException , which, if you quit, you will find out that it cannot be a valid web address.
source share