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 8654141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:42:46+00:00 2026-06-12T14:42:46+00:00

I am using HashSet which has some attributes used for all elements and then

  • 0

I am using HashSet which has some attributes used for all elements and then adding this Hashset to a HashMap corresponding for each element. Additionally few attributes are added for specific elements( ex THEAD ).

But the later added attribute align is present for both Table and THEAD. Is there something wrong in the below code.

private static HashMap<String, Set<String>> ELEMENT_ATTRIBUTE_MAP = 
        new HashMap<String, Set<String>>();

HashSet<String> tableSet = 
            new HashSet<String>(Arrays.asList(new String[]
            {HTMLAttributeName.style.toString(),
             HTMLAttributeName.color.toString(),
             HTMLAttributeName.dir.toString(),
             HTMLAttributeName.bgColor.toString()}));

ELEMENT_ATTRIBUTE_MAP.put(HTMLElementName.TABLE, new HashSet<String>(tableSet));

// Add align only for Head 
tableSet.add(HTMLAttributeName.align.toString());

ELEMENT_ATTRIBUTE_MAP.put(HTMLElementName.THEAD, tableSet);
  • 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-12T14:42:47+00:00Added an answer on June 12, 2026 at 2:42 pm

    Your code should work as you expect. Consider the following (simplified) example which shows the behaviour:

    public static void main(String[] args) {
        String[] array = new String[] {"a", "b", "c"};
        HashSet<String> strings = new HashSet(Arrays.asList(array));
    
        Map<String, Set<String>> map = new HashMap();
        Map<String, Set<String>> newMap = new HashMap();
        Map<String, Set<String>> cloneMap = new HashMap();
    
        map.put("key", strings);
        newMap.put("key", new HashSet(strings));
        cloneMap.put("key", (Set<String>) strings.clone());
    
        strings.add("E");
    
        System.out.println(map); //{key=[E, b, c, a]}
        System.out.println(newMap); //{key=[b, c, a]}
        System.out.println(cloneMap); //{key=[b, c, a]}
    
    }
    

    Note that Java variables are references to objects, not objects themselves, so when you call map.put("key", strings) it is a reference to the underlying HashSet that is passed; hence when you later update the HashSet the HashMap is updated too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed one application which can using hashset concept. I have to override
I am using first array to store all database of numbers where some numbers
I'm building a graph and verify uniqueness of a vertex to add using HashSet<T>
when scanning a file for words and using the built-in hashset class from the
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using CI for the first time and i'm smashing my head with this seemingly
Using the Redis info command, I am able to get all the stats of
Good afternoon In Java, I have HashSet which contain list of Object User which
I was asked in an interview this question LinkedList A has {1,2,3,4,5,6} LinkedList B
I am working on a project that involves me using a HashSet of a

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.