Making an int null

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • plcaine
    New Member
    • Apr 2006
    • 1

    Making an int null

    Hello,

    I am pretty new to Java programming. I am having trouble with trying to convert an integer of value 0 to NULL. I have tried the following and it does not work:

    if (a==0)
    {
    a=NULL;
    }

    Any suggestions? Is it even possible to put an integer back to NULL after it has been initialized? If asking for user input, is there a way for Java to leave the value NULL if the user simply hits "enter?"

    Thank you in advance for your help.
  • alexanderw
    New Member
    • Mar 2009
    • 1

    #2
    int can't be null

    In java int is a primitive type so you can't set it to null.
    try setting it to -1 or 0 instead.

    Also using a=NULL; won't work because java is case sensitive,
    (all keywords are lower case) you need to use a=null; instead.


    Regards,
    Alex

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      If you are using 1.5 or above (you should be) then read about autoboxing.
      With autoboxing you can do sill things like
      [code=java]
      Integer i = 20;
      i = null;
      [/code]

      Comment

      Working...