title: Check if Object has data or not?
body: <p>I am calling method to get data as per passed text that will ping into database.</p>
  
  <p>So I want to check if there is data arrived in object or not.</p>
  
  <p>Code :</p>
  
  <pre><code>Method m = service.getMethodDataByFilter(text);
  </code></pre>
  
  <p>I have tried :</p>
  
  <pre><code>if(m == null){
      System.out.println("In NULL");
  }
  </code></pre>
  
  <p>but it does not entering inside it.</p>
  
  <p>I have also tried :</p>
  
  <pre><code>if(m.getName().isEmpty()){
      System.out.println("In NULL");
  }
  </code></pre>
  
  <p>then it throws <code>NPE</code> in condition because no data received.</p>
  
  <p>So how to check if there is data inside object or not ?</p>
  
  <p>Method Class :</p>
  
  <pre><code>public class Method {
      private Integer id;
      private String name;
      // getter-setter
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Have just try <a href="https://stackoverflow.com/users/1869846/ruchira-gayan-ranaweera">Ruchira</a>    </p>
  
  <pre><code>    if(m== null){
          System.out.println("m is null");
      }else if(m.getName()==null){
          System.out.println("m.getName() is null");
      }else if(m.getName().isEmpty()){
          System.out.println("m.getName() is empty");
      }
  </code></pre>
  
  <p>Still throws same <code>NPE</code>.</p>
  
  <p><strong>FULL Method Code :</strong></p>
  
  <pre><code>public MethodDTO getMethod(String text){
      Method m = service.getMethod(text);
  
      if(m == null){
          System.out.println("m is null");
      }else if(m.getName()==null){
          System.out.println("m.getName() is null");
      }else if(m.getName().isEmpty()){
          System.out.println("m.getName() is empty");
      }
  
      ModelMapper mapper = ModelMap.methodMapper();
      return mapper.map(m, MethodDTO.class);
  }
  </code></pre>