How to check NULL in Java? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to check NULL in Java?

danielm77danielm77 USAPosts: 72Member

Can someone please let me know the standard way to check whether an object is NULL? I'm new to Java. Really appreciate your help.

Tagged:

Comments

  • sunlotussunlotus Posts: 55Member

    Try

    if(object_name.equals(null))
    {
    do something
    }
  • webhostingwebhosting Posts: 2Member

    [code]
    if(obj == null)
    [/code]

  • GouthamKumarGouthamKumar NellorePosts: 17Member

    we can use both == operator or equals operator to check whether an object is null or not.
    Object obj ;
    Here we have created a reference for Object class. So the value will be null.
    if(obj == null)
    System.out.println("obj is not assigned");
    else
    System.out.println("obj is assigned. Carry on");

    0r

    if(obj.equals(null))
    System.out.println("obj is not assigned");
    else
    System.out.println("obj is assigned. Carry on");

Sign In or Register to comment.