February 2nd, 2018

Java 101: Datastructures and algorithms in Java, Part 3

Core Java, Java App Dev, Learn Java, others, Programing, by admin.

In Datastructures and algorithms in Java, Part 2 I introduced a variety of techniques for searching and sorting one-dimensional arrays, which are the simplest arrays. In this article we’ll explore multidimensional arrays. I’ll introduce the three techniques for creating multidimensional arrays, then show you how to use the Matrix Multiplication algorithm to multiply elements in a two-dimensional array. I’ll also introduce ragged arrays and show you why they are popular for big data applications. Finally, I will answer the question of whether an array is or is not a Java object.

Introducing multidimensional arrays

A multidimensional array associates each element in the array with multiple indexes. The most commonly used multidimensional array is the two-dimensional array, also known as a table or matrix. A two-dimensional array associates each of its elements with two indexes.

We can conceptualize a two-dimensional array as a rectangular grid of elements divided into rows and columns. We use the (row, column) notation to identify an element, as shown in Figure 1.

A conceptual view of a two-dimensional array reveals a grid of elements.Jeff Friesen

Figure 1. A conceptual view of a two-dimensional array reveals a grid of elements

Because two-dimensional arrays are so commonly used, I’ll focus on them. What you learn about two-dimensional arrays can be generalized to higher-dimensional ones.

Back Top

Leave a Reply