'Obtaining build status of a jenkins job which is remotely built using java

I am triggering a job remotely using java, I need to trigger another job only after the build of first job is finished/completed(irrespective of the build being successful or not). How to obtain the status of the first build.

I have referred this to trigger jobs remotely. https://support.cloudbees.com/hc/en-us/articles/226852648-How-to-build-a-job-using-the-REST-API-and-Java



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source