Practice Arrays in Java

Work with arrays including creation, traversal, searching, and sorting algorithms.

Work through 22 exercises with starter code, expected output, test cases, and hints.

Arrays exercises

  1. Declare and Print Array Java exercise — Create and display array elements
  2. Sum of Array Java exercise — Calculate the sum of array elements
  3. Find Maximum Java exercise — Find the largest element in an array
  4. Calculate Average Java exercise — Find the average of array elements
  5. Count Even Numbers Java exercise — Count even numbers in an array
  6. Linear Search Java exercise — Find an element in an array
  7. Reverse Array Java exercise — Reverse an array in place
  8. Second Largest Element Java exercise — Find the second largest element
  9. Remove Duplicates Java exercise — Remove duplicate elements from array
  10. Rotate Array Java exercise — Rotate array elements to the right
  11. Merge Sorted Arrays Java exercise — Merge two sorted arrays into one sorted array
  12. Bubble Sort Java exercise — Implement bubble sort algorithm
  13. Selection Sort Java exercise — Implement selection sort algorithm
  14. Binary Search Java exercise — Implement binary search on sorted array
  15. Find Pair with Sum Java exercise — Find two numbers that add up to target
  16. Maximum Subarray Sum Java exercise — Find the maximum sum of a contiguous subarray
  17. Leaders in Array Java exercise — Find all leaders in an array
  18. Equilibrium Index Java exercise — Find index where left sum equals right sum
  19. Wave Array Java exercise — Convert array to wave form
  20. Majority Element Java exercise — Find element appearing more than n/2 times
  21. Left Rotate Array Java exercise — Rotate array elements to the left by k positions
  22. Find Leaders Java exercise — Find elements greater than all elements to their right

Browse the complete Java practice path · Open the online Java compiler