how to assign null to a variable in Java

how to assign null to a variable in Java

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:ww‮tual.w‬turi.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).

Created Time:2017-11-01 12:05:11  Author:lautturi