Use break
:
while (true) {
....
if (obj == null) {
break;
}
....
}
However, if your code looks exactly like you have specified you can use a normal while
loop and change the condition to obj != null
:
while (obj != null) {
....
}
Related Contents:
- What is a NumberFormatException and how can I fix it?
- Declaring variables inside or outside of a loop
- Why do we need break after case statements?
- When should we call System.exit in Java
- How to get out of while loop in java with Scanner method “hasNext” as condition?
- Timer & TimerTask versus Thread + sleep in Java
- Are “while(true)” loops so bad? [closed]
- Difference between break and continue statement
- Java for loop vs. while loop. Performance difference?
- How to handle a SIGTERM
- Java: for(;;) vs. while(true)
- Scanner input validation in while loop
- Please explain the usage of Labeled Statements
- How to use .nextInt() and hasNextInt() in a while loop
- Breaking out of a for loop in Java [closed]
- break a loop if Esc was pressed
- Is it bad practice to use break to exit a loop in Java? [closed]
- Java – Does returning a value break a loop?
- Run code for x seconds in Java?
- Is it possible to read from a InputStream with a timeout?
- How to parse dates in multiple formats using SimpleDateFormat
- How to compare two double values in Java?
- Parse String to Date with Different Format in Java
- Java resource as File
- How to handle invalid SSL certificates with Apache HttpClient? [duplicate]
- NullPointerException in Collectors.toMap with null entry values
- How to use a wildcard in the classpath to add multiple jars? [duplicate]
- How to iterate an ArrayList inside a HashMap using JSTL?
- Should I return a Collection or a Stream?
- How can I access a folder inside of a resource folder from inside my jar File?
- Performance of traditional for loop vs Iterator/foreach in Java
- Java8: Why is it forbidden to define a default method for a method from java.lang.Object
- Difference between & and && in Java? [duplicate]
- How to draw in JPanel? (Swing/graphics Java)
- Default fetch type for one-to-one, many-to-one and one-to-many in Hibernate
- How to disable or bypass Hardware Graphics Acceleration(Prism) in JavaFX
- What does super.paintComponent(g) do?
- LINQ for Java tool [closed]
- Does Java SE 8 have Pairs or Tuples?
- Is -Djava.library.path=… equivalent to System.setProperty(“java.library.path”, …)
- Java parsing XML document gives “Content not allowed in prolog.” error [duplicate]
- How default .equals and .hashCode will work for my classes?
- Convert from one base to another in Java
- Class is not Abstract and does not Override error in Java
- Choosing Java vs Python on Google App Engine
- Can a java lambda have more than 1 parameter?
- CertificateException: No name matching ssl.someUrl.de found
- Running Bash commands in Java
- Android – set TextView TextStyle programmatically?
- scatter plot in jfreechart from database