Consider the below URL as an example. http://www.test1.example.com
Is there any method by which I can get \"example.com\" as an output. I know there is
We have more reliable way of doing the same. There is google library "guava". Add following dependency in your pom.
com.google.guava guava 19.0
Then try
InternetDomainName.from("subdomain.example.co.in").topPrivateDomain().toString()
This will give you "example.co.in"
"example.co.in"