VOOZH about

URL: https://www.geeksforgeeks.org/java/java-program-for-menu-driven-sorting-of-array/

⇱ Java Program for Menu Driven Sorting of Array - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java Program for Menu Driven Sorting of Array

Last Updated : 23 Jul, 2025

In Java, sorting an array consists of arranging the elements in a particular order, such as ascending or descending. This can be achieved using various algorithms like Bubble Sort, Selection Sort, or Insertion Sort. A menu-driven program allows users to select the desired sorting method dynamically.

In this article, we will learn to implement a menu driver array sorting program in Java.

Menu-Driven Sorting of Array in Java

Menu-driven sorting of Array in Java uses a switch statement to allow users to select different sorting algorithms such as Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, Quick Sort, and Heap Sort. Each algorithm is implemented in a separate method, and the user's choice determines which method is used to sort the input array.

Java Program for Menu-Driven Sorting of Array

The following program demonstrates how we can implement a menu driver array sorting program in Java:

Output:

👁 Screenshot-2024-05-25-at-21-15-17-Online-Java-Compiler

Explanation of the above program:

  1. The program starts by taking input from the user to define the array and then displays a menu for selecting one of six different sorting algorithms: Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, Quick Sort, and Heap Sort.
  2. Each sorting algorithm is implemented in a separate method (bubbleSort, selectionSort, insertionSort, mergeSort, quickSort, heapSort).
  3. These methods sort the array in-place.
  4. The user's choice determines which sorting algorithm is called to sort the input array. The sorted array is then printed to the console.
Comment
Article Tags:
Article Tags: