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
You can do this as a simple String manipulation:
String A = "http://www.test1.example.com";
String B = A.substring(A.lastIndexOf('.', A.lastIndexOf('.')-1) + 1);
There is no standard way obtain example.com
from a.b.c.example.com
because such a transformation is generally not useful. There are TLDs that don't allow registrations on the second level; for example all .uk domains. Given news.bbc.co.uk
you'd want to end up with bbc.co.uk
, right?