Suppose you have an input field named "adminNo". What is the difference when you call to getParameter("adminNo") method returns a null value and when it returns an empty string ""?
The value null represents the absence of any object, while the empty string is an object of type String with zero characters. If you try to compare the two, they are not the same.
Sometimes strings can be empty or NULL. The difference is that NULL is used to refer to nothing. However, an empty string is used to point to a unique string with zero length.
The function is meant to return a single value, such as findPerson(). If it was designed to return a collection e.g. findAllOldPeople() then an empty collection is best. A corollary of this is that a function which returns a collection should never return null.
An empty collection isn't the same as null . An empty collection is actually a collection, but there aren't any elements in it yet. null means no collection exists at all.
A call of getParameter("adminNo")
returns an empty String
if the parameter called adminNo
exists but has no value, and null
is returned if there was no such parameter.
From the JavaDoc:
Returns the value of a request parameter as a
String
, ornull
if the parameter does not exist.
What this means in reality is:
null
the HTML form didn't have an input with the parameter name in itString
the HTML form did have an input with the parameter name in it but that no value was set.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With