Why does request.getCookies () return null when no cookies were sent?

According to Javadoc , HttpServletRequest.getCookies() "Returns an array containing all the cookies sent by the client with this request." And it returns null if no cookies were sent.

Is there any specific reason for this behavior other than returning an empty array, which seems more intuitive to me and avoids having to check for null before iterating through the array to find a specific cookie?

+6
source share
1 answer

This was a common Java practice in such situations. The main reason was probably because it was slightly more efficient to return nothing but return an empty list (less work with the garbage collector).

+6
source

All Articles