• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

Break Statement in Java

March 17, 2014 //  by Krishna Srinivasan

This example shows how to use the break statement in Java programming. Break itself a keyword that can be used within a block like for, while, do-while or switch statements. The significance of the break statement is to terminate the current loop and exit the block. It is mostly useful in the loops while we need to come out of the loop when the condition satisfies.

The below example lists the values from an ArrayList and terminates the loop once the “if” condition returns “true”.

package javabeat.net.core;

import java.util.ArrayList;
/**
 * Break statement example
 * @author krishna
 *
 */
public class BreakExample {
	public static void main(String args[]){
		ArrayList<String> days = new ArrayList<String>();
		days.add("Monday");
		days.add("Tuesday");
		days.add("Wednesday");
		days.add("Thursday");
		days.add("Friday");
		days.add("Saturday");
		days.add("Sunday");
		for (String str : days){
			System.out.println("Day : " + str );
			if (str.equals("Friday")){
				System.out.println("Last working day of week. Hurry!!!");
				break;
			}
		}

	}
}

Output

Day : Monday
Day : Tuesday
Day : Wednesday
Day : Thursday
Day : Friday
Last working day of week. Hurry!!!

Category: JavaTag: Core Java

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « Java Dictionary Example
Next Post: Continue Statement in Java »

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

How to Use Optional.ofNullable() Method in Java

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact