Collecting adjacent cells in a 2D grid implemented as a 1D list
Looks good, ship it.

Certainly cols is an accurate name, but in this context sometimes people prefer to refer to it as stride.

It's close to the initial default, but still, since you know the max size you might specify a capacity: new ArrayList&lt;&gt;(8);

Modulo can be slightly expensive. Maybe you want to assign the result to a temp variable, or maybe you trust that JIT already did that for you.

The sequential memory references to {l&amp;u, u, u&amp;r} are cache friendly. The reverse sequence of addresses, {r&amp;d, d, d&amp;l} is perhaps backwards from what you prefer.