title: How to convert HttpStatus code to int in Java?
body: <p>I am using RestTemplate <code>postForEntity</code> method to <code>POST</code> to an endpoint. If <code>POST</code> is success, the <code>statusCode variable</code> should change its value to status code of <code>201</code>, but I am having difficulty converting HttpStatus to int in Java. I am getting error <code>Cannot cast from HttpStatus to int</code>  I could not get any solutions regarding this. Any suggestions are appreciated.</p>
  
  <p>Here is my code</p>
  
  <pre><code>import org.springframework.http.HttpStatus;
  
      public int postJson(Set&lt;String&gt; data) {
          int statusCode;
          try {
  
              ResponseEntity&lt;String&gt; result = restTemplate.postForEntity(url,new HttpEntity&lt;&gt;(request, getHttpHeaders()), String.class);
  
              statusCode = (int) result.getStatusCode();   
  
          } catch (Exception e) {
              LOGGER.error("No Post", e);
          }
          return statusCode;
      }
  }
  
  </code></pre>