Java HttpCookie getMaxAge() Method

22 Mar 2025 | 2 min read

The getMaxAge() method of Java HttpCookie class is used to return the maximum age of the cookie within the seconds. By default, -1 represents that the given cookie exists until the browser is shut down.

Syntax

Parameter

N.A.

Return

The above method is used to return an integer which specifies the maximum age of the cookie within seconds.

Example 1

Output:

 The maximum age of the cookie is given as: 1700 

Example 2

Output:

 The maximum age of the first cookie is given as: 2000 The maximum age of the second cookie is given as: 1000 

Example 3

Output:

 The maximum age of the cookie is given as: -1