Java tutorial
//package com.java2s; public class Main { /** * Make sure URL starts with http:// or https:// and has a slash * for the path if the path is missing. Examples: * * foo.org -> http://foo.org/ * http://foo.org -> http://foo.org/ * * @param url * @return */ public static String fixUrl(String url) { if (!url.startsWith("http://") && !url.startsWith("https://")) url = "http://" + url; // Make sure there are at least three slashes (two in http://) int count = 0; for (int i = 0; i < url.length() && count < 3; i++) { if (url.charAt(i) == '/') count++; } if (count == 3) return url; else return url + "/"; } }