title: how to check multiple string value are empty or blank at one shot using java
body: <p>I've scenario to validate given input param is empty or not, I've list of fields with datatype <strong>string</strong> and <strong>date</strong> - <code>productId,productName,productType,productRating,productSellDate and productReturnDate</code></p>
  <p>I want to check these input params are <code>null</code> or <code>empty</code> or <code>blank</code> for each field and if any one of the field is <code>empty</code> or <code>blank</code> or <code>null</code> - it should throw <code>NullPointerException</code> with field name.</p>
  <p>Please find my code below - since I'm new to Java please apologize for the coding standard. I don't know how to get the field name which has <code>empty</code> or <code>null</code> when I throw <code>NullPointerException</code></p>
  <p>And I'm calling <code>validate</code> and <code>validateDate</code> for each string, is there any option to validate all these param in one go?</p>
  <p>Please suggest if there is any better way of writing the below piece of code. Appreciated your help in advance! Thanks.</p>
  <pre><code>import java.util.Date;
  
  public class Test {
  
      public static void main(String[] args) {
          String productId = &quot;&quot;;
          String productName = &quot;Apple&quot;;
          String productType = &quot;Electronics&quot;;
          String productRating = &quot;Good&quot;;
          Date productSellDate = new Date();
          Date productReturnDate = new Date();
  
          System.out.println(validate(productId));
          System.out.println(validate(productName));
          System.out.println(validate(productType));
          System.out.println(validate(productRating));
  
          System.out.println(validateDate(productSellDate));
          System.out.println(validateDate(productReturnDate));
  
      }
  
  
      private static String validate(String s) {
          if (s.isBlank() || s.isEmpty()) {
              throw new NullPointerException(&quot;input param is empty&quot;); // how to get the string field name which is empty or null or blank
          } else {
              return &quot;valid&quot;;
          }
      }
  
  
      private static String validateDate(Date d) {
          if (d == null) {
              throw new NullPointerException(&quot;sell or return date is empty&quot;); // how to get the date field name which is empty or null or blank
          } else {
              return &quot;date is valid&quot;;
          }
      }
  }
  </code></pre>