How to identify the top level domain of a URL object using java?

trinity picture trinity · Jan 26, 2010 · Viewed 10.8k times · Source

Given this :

URL u=new URL("someURL");

How do i identify the top level domain of the URL..

Answer

jeremie picture jeremie · Aug 23, 2019

Guava provides a nice utility for this. It works as follow:

InternetDomainName.from("someurl.co.uk").publicSuffix() will get you co.uk InternetDomainName.from("someurl.de").publicSuffix() will get you de