Break Statement in Java

Published on July 17, 2015 by abundantcode

Filed under Java

Last modified July 17, 2015

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 5723 times

Java provides the break keyword that is used by the developers to exit out of the loop before the actual completion of the loop. Additionally , the break keyword can also be used to jump out of a single case in switch statement.

Break Statement in Java

Below is a sample code snippet demonstrating the usage of the break statement in java.

package com.abundantcode;

import java.util.ArrayList;
import java.util.List;
public class Main {

    public static void main(String[] args)
    {
        List<String> input = new ArrayList<String>();
        input.add("Abundantcode.com");
        input.add("Programming Website");
        input.add("Java Tutorials");
        for(String item:input)
        {
            System.out.println(item);
            break;
        }
    }
}

 

image

Leave a Comment


x

You might be Interested in these Posts

Video - Angular Router - Brian Ford

Video - Angular Router - Brian Ford http://www.youtube.com/watch?v=sfV0ApyN5fM ...

Video - An Angular2 Todo App: First look at App Development in Angular2

In this screencast , David East , one of the core contributor of the Angular provides a glimpse of A...

Video - Getting started with Angular 2

In this screencast , Alex Eagle , developer on the Angular team talks about Angular 2 developer prev...