File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes retrieve values from hashmap in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "retrieve values from hashmap in java " Watch "retrieve values from hashmap in java " New topic

retrieve values from hashmap in java

Suvishala Hari

Joined: Apr 24, 2011
Posts: 3
I have a XML file with many copies of table node structure as below:

As it is not an efficient manner to traverse the file for each time to fetch the details of each node for the queries in the program, I used the nested hashmap concept to store the details while traversing the XML file for the first time. The structure I used is as below:

But the problem I’m facing now is regarding retrieving the Value part using the nested Keys.
For example, If I need the value of Slno Key, I have to specify TblID, SelectColumns, Slno in nested form like:

This is unconvinent to use in a program. Please suggest a solution but don’t tell that iterators are available. As I’ve to fetch the individual value from the map according to the need of my program.
Thanks in advance,
Suvishala Hari
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

You could use XPath expressions to traverse the DOM directly. However if your desire to avoid processing the DOM repeatedly is based in reality, and is not just premature optimization based on guesswork or rumours, and you don't like the programming you have let yourself in for, then you're going to have to change your data structure.

Which of course was your question -- how should you change it? Well, no serious designer would create a design based on a single sample of its input. So you're going to have to explain a bit more about the structure of the documents you expect to process.
Suvishala Hari

Joined: Apr 24, 2011
Posts: 3
Thanks Paul....

The structure of my file is same as the structure of the single table node that I've written above. The table node repeats depending on as many departments have the mail details in the database, that is mail details table for each department is separate. So the table node repeats as the column names of each table are different.

The purpose of XML file is to store the column name information of each table associated with table name and its ID and to serve as an input to the query statements.
I'm not using the entire information of the XML in my queries. I'm first checking which of the department have the privilege to send mails and collecting their IDs. Then I've to match the IDs that is in my XML and then only the column name information of those department is fetched from my XML. This is all about my program.

Please suggest appropriate solution.
Suvishala Hari

Joined: Apr 24, 2011
Posts: 3
Please reply, I'm waiting for the suggestion.
I agree. Here's the link:
subject: retrieve values from hashmap in java
It's not a secret anymore!