Sometimes, we might need extract domain name such as www.google.com from the www.google.com/search=searchQuery. In android java, the code below can do it. It will output only the domain name after stripping other characters
Java Code for getting host domain name from URL
URI uri = null; try { uri = new URI(url); String domain = uri.getHost(); Toast.makeText(mContext, domain, Toast.LENGTH_SHORT).show(); } catch (URISyntaxException e) { e.printStackTrace(); }