Menu Close


Java: 2D Arrays

Today I have for you an interesting example. It deals with 2D arrays and the use of classes and their methods.

You can refresh your memory about regular arrays (also known as 1D array) in this article.

The difference between a 2D array and a regular array is that in a 2D array there are 2 dimensions height (columns) and width (rows). Imagine that you have a series of 1D arrays, one stacked on top of the other. On each row you have an array made up of however many elements. Each element exists in a column.

The above program represents a seating chart, a stands for Available, X stands for a taken seat. The class “PerformanceSeating” is able to fill seats, make them available and print a representation to console. It is also able to tell the user how many booked/available seats there are.