From the course: Java 8+ Essential Training: Syntax and Structure

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Create looping code blocks

Create looping code blocks - Java Tutorial

From the course: Java 8+ Essential Training: Syntax and Structure

Start my 1-month free trial

Create looping code blocks

- [Instructor] Java provides a number of ways of looping through collections of data. In this project, loops, I've created an array of strings. The array is private to the class, that means it can't be accessed outside of the class, and it's static which means it belongs to the definition of the class rather than to an instance of the class. It's an array of strings indicated by the type and the pair of brackets, and the name is months. To create the array I've used notation that uses braces wrapped around a comma delimited list. So I have an array containing 12 values. One value for each month of the year. I'm going to demonstrate how to loop through this data using four different kinds of loops: an incrementing loop, a for each loop, a while loop, and a do while loop. And I'll start with an incrementing loop. IntelliJ IDEA lets you create this code very quickly. Type fori, IntelliJ IDEA calls this an iteration loop. Press Enter or Return and that expands to a simple loop. An…

Contents