Skip to content

Latest commit

 

History

History
12 lines (9 loc) · 1.43 KB

File metadata and controls

12 lines (9 loc) · 1.43 KB

This Java program is designed to manage a list of students, each represented by a demo object with a roll number (num) and a name (name). The main functionality of the program is to sort the students based on different criteria.

Here's a summary of what the code does:

  1. It prompts the user to enter the number of students.
  2. For each student, it asks the user to input the student's name and creates a new demo object with the roll number (which is the current index i) and the inputted name. This object is then added to the list li.
  3. The program sorts the list li twice:
    • First, it sorts the students alphabetically by the first character of their names using a custom Comparator.
    • Then, it sorts the students by their roll numbers using another custom Comparator.
  4. After each sort, the program prints out the list of students.

This program can be used in educational institutions or any other scenario where there's a need to manage and sort a list of individuals based on different criteria. For example, a teacher could use this program to sort students by name for attendance purposes, and then sort by roll number for grading purposes. However, please note that the toString method in the demo class needs to be modified to return a string representation of the demo object for the sorted list to be printed correctly. Currently, it's printing the details but returning the default toString from the Object class.