Online Java Compiler By
JavaTpoint.com
import java.net.HttpCookie; public class JavaHttpCookieDomainMatchesExample3 { public static void main(String[] args) { String domain1 = "www.google.com", host1 = "www.google.com"; String domain2 = "www.javatpoint.com", host2="www.tutorial.com"; HttpCookie cookie1 = new HttpCookie("Employee1", "5"); HttpCookie cookie2 = new HttpCookie("Employee2", "10"); //Returns true if the domain matches. Otherwise, returns false. System.out.println("Tests whether the first host name lies in the first domain or not: "+cookie1.domainMatches(domain1, host1)); System.out.println("Tests whether the second host name lies in the second domain or not: "+cookie2.domainMatches(domain2, host2)); } }
Output