Reader small image

You're reading from  Learning Java by Building Android Games - Third Edition

Product typeBook
Published inMar 2021
Reading LevelBeginner
PublisherPackt
ISBN-139781800565869
Edition3rd Edition
Languages
Right arrow
Author (1)
John Horton
John Horton
author image
John Horton

John Horton is a programming and gaming enthusiast based in the UK. He has a passion for writing apps, games, books, and blog articles. He is the founder of Game Code School.
Read more about John Horton

Right arrow

Entering the nth dimension with arrays

We very briefly mentioned that an array can even hold other arrays at each position. And of course, if an array holds lots of arrays that in turn hold lots of some other type, how do we access the values in the contained arrays? And why would we ever need this anyway? Look at this next example to see where multidimensional arrays can be useful.

Multidimensional array mini app

Let's make a simple multidimensional array example. You can get the working project for this example on the GitHub repo. It is in Chapter 12/Multidimensional Array Example/MainActivity.java.

Create a project with an empty activity and call it Multidimensional Array Example. Leave the activity name as the default; it is not important.

After the call to super.onCreate… in the onCreate method, declare and initialize a two-dimensional array like this:

// Random object for generating question numbers
Random randInt = new Random();
// a variable to hold...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Learning Java by Building Android Games - Third Edition
Published in: Mar 2021Publisher: PacktISBN-13: 9781800565869

Author (1)

author image
John Horton

John Horton is a programming and gaming enthusiast based in the UK. He has a passion for writing apps, games, books, and blog articles. He is the founder of Game Code School.
Read more about John Horton