最好的方法是使用正则表达式,如下所示:
public static final String URL_REGEX = "^((https?|ftp)://|(www|ftp)\.)?[a-z0-9-]+(\.[a-z0-9-]+)+([/?].*)?$";Pattern p = Pattern.compile(URL_REGEX);Matcher m = p.matcher("example.com");//replace with string to compareif(m.find()) { System.out.println("String contains URL");}


