What is the best way to exit/terminate a while loop in Java?
For example, my code is currently as follows:
while(true){ if(obj == null){
Take a look at the Java™ Tutorials by Oracle.
But basically, as dacwe said, use break.
break
If you can it is often clearer to avoid using break and put the check as a condition of the while loop, or using something like a do while loop. This isn't always possible though.