Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7998549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:14:28+00:00 2026-06-04T15:14:28+00:00

Hi all I have been trying to fix this but could not fix, the

  • 0

Hi all I have been trying to fix this but could not fix, the problem is remove is not working in hashmap.

Please see the below code.

 package com.org.common;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@SuppressWarnings("unused")
class Workindays {
    public static int findNoOfDays(int year, int month, int day) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month - 1, day);
        int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        return days;
    }
    public static Map<String, String> getHolydaysMap(int year, int month, int day) {
        //connect with database and check whether the date is holyday query is = SELECT * FROM holiday_calendar h WHERE date >='2008-10-01' AND date <='2008-10-30' AND type='Fixed';
        Map<String, String> holydaysMap = new LinkedHashMap<String,String>(); 

        holydaysMap.put("20","17-04-2012");
        holydaysMap.put("10","25-04-2012");
        return holydaysMap;
    }
    public static Map<String, String> getWorkingDaysMap(int year, int month, int day){
        int totalworkingdays=0,noofdays=0;
        String nameofday = "";
        ConcurrentHashMap<String,String> workingDaysMap = new ConcurrentHashMap<String,String>();
        Map<String,String> holyDayMap = new LinkedHashMap<String,String>();
        noofdays = findNoOfDays(year,month,day);
        holyDayMap = getHolydaysMap(year,month,day);

        for (int i = 1; i <= noofdays; i++) {
            Date date = (new GregorianCalendar(year,month - 1, i)).getTime(); // year,month,day
            SimpleDateFormat f = new SimpleDateFormat("EEEE");
            nameofday = f.format(date);
            String formatedDate = i+"-"+month+"-"+year;
            if(!(nameofday.equals("Saturday") || nameofday.equals("Sunday"))){
                workingDaysMap.put(String.valueOf(i),formatedDate);
                totalworkingdays++;
            }
        }
        workingDaysMap.put("totalworkingdays", String.valueOf(totalworkingdays));

        System.out.println("removeHolyday : "+removeHoliday(workingDaysMap,holyDayMap));
        return workingDaysMap;
    }
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static Map removeHoliday(ConcurrentHashMap daysMap, Map holydayMap) {
        Iterator<Map.Entry> holyDayiterator = holydayMap.entrySet().iterator();
        while (holyDayiterator.hasNext()) {
            Map.Entry holyDayEntry = holyDayiterator.next();

            Iterator<Map.Entry> daysiterator = daysMap.entrySet().iterator();
            while (daysiterator.hasNext()) {
                Map.Entry daysEntry = daysiterator.next();
                 if(daysEntry.getKey().equals(holyDayEntry.getKey()))
                      daysMap.remove(holyDayEntry.getKey());
            }
        }
        return daysMap;
    }
    @SuppressWarnings({ "rawtypes" })
    public static void main(String[] args) {
        String delimiter = null, dateValues[] = null, startDate = "01-04-2012";
        int year = 0,month=0,day=0,totalworkingdays = 0;
        Map workingDaysMap = new LinkedHashMap<String,String>();

        startDate = "01-04-2012";
        delimiter = "-";
        dateValues = startDate.split(delimiter);

        year = Integer.parseInt(dateValues[2]);
        month = Integer.parseInt(dateValues[1]);
        day = Integer.parseInt(dateValues[0]);

        workingDaysMap = getWorkingDaysMap(year, month, day);
        //System.out.println("workingdays map : "+workingDaysMap);

    }
}

this is the method i call to remove a value

removeHolyday

I have just given sample value to test in the following method.

getHolydaysMap

Please help.

EDIT :
Thanks guys for all who have taken their valueable time to answer, upvote and downvote.i have changed the code and it is working fine now,

updated working code.

Regards
Antony

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:14:30+00:00Added an answer on June 4, 2026 at 3:14 pm

    You can use ConcurrentHashMap to do this,

    public static Map removeHolyday(ConcurrentHashMap daysMap,Map holydayMap){

    EDIT : use the following code to do,

    public static Map removeHoliday(ConcurrentHashMap daysMap, Map holydayMap) {
            Iterator<Map.Entry> holyDayiterator = holydayMap.entrySet().iterator();
            while (holyDayiterator.hasNext()) {
                Map.Entry holyDayEntry = holyDayiterator.next();
                if(daysMap.containsKey(holyDayEntry.getKey())){
                    daysMap.remove(holyDayEntry.getKey());
                }
            }
            return daysMap;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to fix this problem for a while and have exhausted all
So, I have been trying to fix this for about two months. It all
Hey all, i have been trying for a few minutes on this problem and
I have been trying to fix this problem for hours. My app keeps crashing
Ok so I have been trying to fix this for days, and I'm not
I have been trying to fix this on my site but I am having
I have been trying to fix this issue for weeks but I'm at the
I've been struggling for weeks trying to fix this problem, but I haven't found
I've been beating my head against the desk all day trying to fix this!!!
I've been trying to get this working for a couple of hours now but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.