What is Abstraction?
You have now met two ways of holding a collection: the plain array, and the dynamic array we just described. They are built differently, but they both rely on the same idea. That idea is called abstraction.
Abstraction is separating what something does from how it does it. You get a simple interface to work with, and the details underneath are hidden from you.
We have already relied on this idea twice. Let’s name what is hidden in each case.
The array hides the hardware
When you write numbers[2], you get the third element back. You do not think about where that element sits in memory. Recall what actually happens underneath: the computer takes the array’s starting address and adds 2 × (bytes per element) to find the address of the element at index 2.
That work does not disappear. The array just does it for you. You write numbers[2], and the machine does the address arithmetic. That is the abstraction.
The dynamic array hides the bookkeeping
The dynamic array goes one step further. With a plain array you still manage size yourself: commit to a capacity up front, track how full you are, and allocate a bigger array and copy everything across when you run out of room.
The dynamic array does all of that for you. You call add and it does that, even if the underlying array is at capacity. The allocating, the copying, and the counting stay hidden. You think about your data, not about how it is stored.
Abstraction as modeling
There is a second sense of the word worth knowing. Arrays also abstract ideas from mathematics. A one-dimensional array is how we write a vector like [3, 4, 5] in code, and a two-dimensional array (an array of arrays) is how we write a matrix, a grid, or a table.
// A 3x3 grid (like a tic-tac-toe board)
char[][] grid = {
{'X', 'O', 'X'},
{'O', 'X', 'O'},
{'X', 'O', 'X'}
};
System.out.println(grid[1][2]); // row 1, column 2: O
System.out.println(grid.length); // number of rows: 3
System.out.println(grid[0].length); // number of columns: 3
Here the array is a model: a way to put a mathematical object into code. That is not the same as hiding the implementation, but it is related. In both cases a simple notation stands in for something more involved.
In fact, arrays were added to programming languages because of this mathematical connection.