passing 2D collection objects  into 1D collection objects

Posted on 2012-09-06
Last Modified: 2012-10-01
when, where, how, why we need to passing 2D collection objects like hashmap, hashtable, properties into 1D collection objects like arraylist, vector, hasset, sorted set etc  and reading back again. What are the practical uses, advantages, disadvanages of doing it.Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
Question by:gudii9
    LVL 17

    Accepted Solution

    Generally this sort of thing is done when you want to extract all of the keys, or all of the values and do something with them and the key is no longer relevant.

    Depending on what processing you want to do with the list will depend on how effective or extra processing is required.  For example, if you are deleting a whole lot of items from a large dictionary, it may be quicker to extract all the values to a list and remove the items from  the list and then recreate the dictionary/hashmap.

    Sometimes you can do this sort of thing to rebalance a TreeMap or something similar where aver time the tree becomes unbalanced because a lot of work is happening on a few node groups.
    LVL 7

    Author Comment

    >>Sometimes you can do this sort of thing to rebalance a TreeMap or something similar where aver time the tree becomes unbalanced because a lot of work is happening on a few node groups.

    can you please elaborate on above point. I am not clear on that.
    LVL 17

    Expert Comment

    Think of a tree as a set of roots for a tree.

    As things get added to the tree they get added to one side or the other of the tree depending on where they fall between the existing nodes.  If you delete a lot of nodes from one side of the tree roots, then it is like cutting of one set of branches of a tree.  The tree no longer has the same number of nodes (branches/root branches) evenly spaced over a tree.

    A similar thing happens when lots of additions occur between the keys that sit on one side of the tree.  That side of the tree becomes unbalanced and a tree search needs to descend further nodes to find the correct key value.  This slows down the performance of a tree.

    Most tree algorithms will have a capacity to rebalance, some automatically, some manually to adjust the nodes of the tree back to something approximating equality.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    This video teaches viewers about errors in exception handling.
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now