StudyLover
  • Home
  • Study Zone
  • Features
    • Workout Interval Timer
    • Typing Tutor
  • Profiles
  • Contact us
  • Sign in
StudyLover The ArrayList Manager
Download
  1. Java
  2. Programs
The Interaction Tracker : The Unique Identity Set
Programs
Initiative: To perform dynamic data operations (CRUD) using the ArrayList collection.
import java.util.*; // Import utility classes for Collections

public class ArrayListManager { // Define class for dynamic list operations
    public static void main(String[] args) { // Program entry point
        System.out.println("--- Dynamic Staff Management ---"); // Print system header
        
        ArrayList staff = new ArrayList<>(); // Initialize a dynamic array list of strings
        
        // 1. CREATE (Adding items)
        staff.add("Amit"); // Add Amit to the list
        staff.add("Binu"); // Add Binu to the list
        staff.add("Chetan"); // Add Chetan to the list
        System.out.println("Initial List: " + staff); // Print current contents
        
        // 2. READ (Accessing items)
        String head = staff.get(0); // Retrieve the item at the first index (0)
        System.out.println("Staff at Index 0: " + head); // Show the result
        
        // 3. UPDATE (Modifying items)
        staff.set(1, "Binu (Promoted)"); // Replace the item at index 1 with a new string
        System.out.println("After Promotion: " + staff); // Print updated list
        
        // 4. DELETE (Removing items)
        staff.remove("Chetan"); // Search and remove the specific object "Chetan"
        System.out.println("After Resignation: " + staff); // Print current list state
        
        // 5. SORTING & ITERATING
        Collections.sort(staff); // Sort the strings alphabetically
        System.out.println("\nSorted List:"); // Section header
        
        Iterator it = staff.iterator(); // Create an iterator for safe traversal
        while (it.hasNext()) { // Loop as long as there is another element
            System.out.println(">> " + it.next()); // Print the next element from the list
        } // End of iterator loop
        
        System.out.println("Final Count: " + staff.size()); // Show total number of items
        System.out.println("Management Lab: Finished."); // Final log for collection lab
    } // End of main method
} // End of ArrayListManager class
The Interaction Tracker The Unique Identity Set
Our Products & Services
  • Home
Connect with us
  • Contact us
  • info.studylover@gmail.com

StudyLover - About us

The Best knowledge for Best people.

Copyright © StudyLover
Powered by Odoo - Create a free website