CompSci.rocks
LearnJava

Java Array Algorithms

A roadmap to the core array algorithms every Java student should know, from finding a minimum or maximum to searching for a value.

Arrays show up everywhere in a first-year Java course, and a handful of algorithms come up again and again once you start working with them: finding the smallest or largest value, adding everything up, averaging it, checking whether every value is unique, swapping two values, and searching for something specific.

None of these algorithms are long or complicated on their own, but they're worth learning well, because so many bigger programs are just these patterns combined and adapted. Once "loop through the array, compare or accumulate as you go" clicks, a huge number of array problems start to look familiar.

This series walks through each one, with working Java code and an explanation of why it works.

What's in this series

Jump straight to whichever one you need, or work through them in order using the list at the bottom of each page.