In Java, you can assign the null
value to a variable to indicate that it does not currently refer to an object. To do this, you simply use the null
keyword.
Here's an example of how to assign null
to a variable in Java:
String s = null;Source:wwtual.wturi.com
This will assign the null
value to the String
variable s
, indicating that it does not currently refer to an object.
It's important to note that you can only assign null
to reference variables (such as object references or array references) in Java. You cannot assign null
to primitive variables (such as int
or char
).