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
- Minimum / Maximum Algorithm — find the smallest or largest value in an array
- Sum Algorithm — add up every value in an array
- Average Algorithm — build on the sum algorithm to find the average
- Unique Algorithm — check whether every value in an array is different
- Swap Values — swap two values in an array, and why the obvious way doesn't work
- Linear Search — search an array for a specific value
Jump straight to whichever one you need, or work through them in order using the list at the bottom of each page.
Array Algorithms
A series of algorithms used in array manipulation.