473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to iterate a hashmap with key hashmap

Hello, I need help. I have the following hashmap:

Expand|Select|Wrap|Line Numbers
  1. HashMap<HashMap<Dimension, Integer>, String> mapList = new HashMap<HashMap<Dimension, Integer>, String>();
I want to extract Dimesion from the key, where the Integer is "1", and String from the value.

How could I iterate it?
I wrote that, but it doesn't work at the way I expected:

Expand|Select|Wrap|Line Numbers
  1. HashMap<Dimension, String> singleValues = new HashMap<Dimension, String>();
  2. for (Map.Entry<HashMap<Dimension, Integer>, String> entry : mapList.entrySet()) {
  3.   Iterator iter = entry.getKey().entrySet().iterator();
  4.   while (iter.hasNext()) {
  5.     Map.Entry<Dimension, Integer> innerEntry = (Map.Entry<Dimension, Integer>) iter.next();
  6.     if (innerEntry.getValue().equals(1)) {
  7.       singleValues.put(innerEntry.getKey(), entry.getValue());
  8.       System.out.println(innerEntry.getKey() + " : " +
  9.       entry.getValue());
  10.  
  11.     }
  12.   }
  13. }
Thanks in advance
Oct 7 '09 #1
1 5595
r035198x
13,262 8TB
Your code smells a bit. Why do you have a Map<Map>? Also trying to search the map by value rather than the key adds a bit of bad odour.
What problem are these maps trying to solve?
Oct 7 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Welson Sun | last post by:
Hi, I am new to UML, I would like to know how can represent JAVA's ArrayList and HashMap with UML diagram? How can I represent the element's class in the ArrayList/HashMap? How is the key in the...
1
by: Christian Gollwitzer | last post by:
Hi, I'm trying to loop over the elements in a hashmap of the STL-implementation by SGI. The point is, that because the key/value pair is stored as std::pair in the COntainer, the code becomes...
4
by: David | last post by:
Hi, I have created the following HashMap class. class HashMap: public hash_map<string, string, HashString, HashStringCompare> { public: HashMap(): hash_map<string, string, HashString,...
2
by: xor | last post by:
I'm doing up a school project using java, and am a little new to it (I've worked with other languages for years though). I've seen code posted by the instructor using HashMap like this... ...
13
by: shiniskumar | last post by:
Ive got a collection that is populated by some key/value pairs. How can i iterate ie to get its each key/value pair?
6
by: bumrag | last post by:
This is the car dealership object relating to the coursework, there is also a separate object named car that i think i need to link to. The problem is on the addcar() method. Any help would be...
4
by: panos100m | last post by:
Hi these are the conents of my hashmap printing out the entrySet. entrySet1: OrderDate=10/30/2007, entrySet2: Level_0={Item_0={ItemTotal= 3.99, ItemName=test® in, ShipDate=10/31/2007,...
15
by: lbrtchx | last post by:
Hi, ~ I have found myself in need of some code resembling a Hashmap ~ This is easily done in Java this way: ~ import java.util.*; // __ public class JMith00Test{
3
dlite922
by: dlite922 | last post by:
I could have this done in php in three lines of code but in Java here's what I need to do: English Looping through list of words I call a function that returns a HashSet of movie titles that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.