Java Objects to string and handle null

Description

Java Objects to string and handle null

import java.util.Objects;

public class Main {

   public static void main(String[] args) {
      String item = "demo2s.com";
      //from   w  ww .j av a 2  s  .  c o m
      item = null;
      
      System.out.println("toString: " + Objects.toString(item)); 
      System.out.println("toString: " + Objects.toString(item, "Item is null")); 

  }
}



PreviousNext

Related