From the course: Java 8 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Using two-dimensional arrays - Java Tutorial
From the course: Java 8 Essential Training
Using two-dimensional arrays
- Java supports the use of multidimensional arrays using the same sort of syntax that you use with simple arrays. But instead of using a single pair of brackets, you add brackets as you add dimensions to the array. In this project, MultiArrays, I'll declare a String array and I'll start with a pair of brackets just like I did before, but this time, I'll add a second pair of brackets. This will be a two-dimensional array. I'll name the array states and then as I did before, I'll initialize it with the new keyword and the data type. But this time when I select the data type, IntelliJ IDEA adds two pairs of brackets to match the original declaration and I can set the size of both dimensions of the array here. I'll set the outer array as 3 items and each item within that array will have 2 sub items. And so now I have a two-dimensional array. Next, I'll set the values. I'll reference an item in the array, starting with the array name, and then once again, two pairs of brackets. For the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.