0% found this document useful (0 votes)
9 views2 pages

Hashset

Uploaded by

harinielluru09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Hashset

Uploaded by

harinielluru09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

HashSet;

import java.util.Scanner;

class HashsetEx {

public static void main(String[] args) {

HashSet<String> employeeIDs = new HashSet<>();

Scanner s = new Scanner(System.in);

while (true) {

System.out.println("Menu:");

System.out.println("1. Add employee ID");

System.out.println("2. Remove employee ID");

System.out.println("3. Check existence of an employee ID");

System.out.println("4. Exit");

System.out.print("Enter your choice (1-4): ");

int ch = s.nextInt();

switch (ch) {

case 1:

System.out.print("Enter the employee ID to add: ");

String newID = s.next();

if (employeeIDs.add(newID)) {

System.out.println("Employee ID " + newID + " added successfully!");

} else {

System.out.println("Employee ID " + newID + " already exists!");

break;

case 2:

System.out.print("Enter the employee ID to remove: ");

String removeID = s.next();

if (employeeIDs.remove(removeID)) {
System.out.println("Employee ID " + removeID + " removed successfully!");

} else {

System.out.println("Employee ID " + removeID + " not found!");

break;

case 3:

System.out.print("Enter the employee ID to check existence: ");

String checkID = s.next();

if (employeeIDs.contains(checkID)) {

System.out.println("Employee ID " + checkID + " exists!");

} else {

System.out.println("Employee ID " + checkID + " does not exist!");

break;

case 4:

System.out.println("Exiting the program.");

System.exit(0);

default:

System.out.println("Invalid choice. Please enter a number between 1 and 4.");

You might also like