String query = URLEncoder.encode("apples oranges", "utf-8"); String url = "http://stackoverflow.com/search?q=" + query;