hashmap

Need a Java map/table with multiple keys to one value. Value is commonly altered

What I need is a collection which allows multiple keys to access a single object. I need to apply frequent alterations to this object. It also must be efficient for 500k+ entries. ...

Dealing with maps, equals() and hashCodes(). How efficient is this ?

I'm writing something which will receive quite a number of transactions per second. For every transaction that comes in, a reference is made to a map which key values are the id and a bean which will help process that particular transaction. Basically each transaction comes in bearing an id, a look up will be done to the map to retrieve ...

C# Java HashMap equivalent

Coming from a Java world into a C# one is there a HashMap equivalent? If not what would you recommend? ...

Hashtable in java is giving me the last stored value, but not the right value

Sorry this is kinda long, but I needed to get the right scenario. This outputs all C's, why?? thanks in advance import java.util.Hashtable; public class Main { public static ContainsTheHash containsthehash = new ContainsTheHash(); public static StoresValues storesvalues = new StoresValues(); public static GetsValuesAn...

Performance of HashMap with different initial capacity and load factor

Here is my situation. I am using two java.util.HashMap to store some frequently used data in a Java web app running on Tomcat. I know the exact number of entries into each Hashmap. The keys will be strings, and ints respectively. My question is, what is the best way to set the initial capacity and loadfactor? Should I set the capacit...

java generics/inheritance in nested hashmap

hi all, if i have two hashmaps, of types HashMap<Integer, HashMap<Integer, Police>> time_id_police; HashMap<Integer, HashMap<Integer, Ambulance>> time_id_ambulance; where Police and Ambulance both extend Rescue, how can i have a method like HashMap<Integer, HashMap<Integer, Rescue>> getRescue(){ if (a) return time_id_police; ...

Correct way to initialize HashMap and can HashMap hold different value types?

So I have 2 questions about HashMaps in Java: (1) What is the correct way to initialize a HashMap? I think it might be best in my situation to use: HashMap x = new HashMap(); But Eclipse keeps suggesting that I use: HashMap<something, something> map = new HashMap(); which is better? (2) Can a HashMap hold different types of objec...

Java - HashMap vs Map objects

What is the difference between the following maps I create (in another question, people answered using them seemingly interchangeably and I'm wondering if/how they are different): HashMap<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>(); ...

How can I use MATLAB arrays as keys to the HashMap java objects?

The put function works fine but the get function does not. Apparently I don't know the trick. >> X = [ 1, 2, 3]; >> M = java.util.HashMap; >> M.put(X,1); >> M.get([1,2,3]) ans = [] I have searched and read many posts but could not find a solution to this problem. It would be great if someone can let me know the trick. ...

Hashmap and hashtable in multithreaded environment

I am really confused on how these 2 collections behave in multithreaded environment. Hash table is synchronized that means no 2 threads will be updating its value simultaneously right? ...

Performance ConcurrentHashmap vs HashMap

How is the performance of ConcurrentHashMap compared to HashMap, especially .get() operation (I'm especially interested for the case of only few items, in the range between maybe 0-5000)? Is there any reason not to use ConcurrentHashMap instead of HashMap? (I know that null values aren't allowed) Update just to clarify, obviously the...

Java Hashmap: How to get key from value?

If I have the value "foo", and a hashmap ftw for which ftw.containsValue("foo") returns true, how can I get the corresponding key? Do I have to loop through the hashmap? What is the best way to do that? ...

Best way to create large hashmap at compile time (C++)?

In my application, I need a hash map mapping strings to a large number of static objects. The mappings remain fixed for the duration of the application. Is there an easy way to pre-generate the mappings at compile time rather than building it element-by-element when the application starts? ...

Java Hashmap Iteration: Look at two values at once?

I have this loop: for (Map.Entry<Integer, String> entry: collection.entrySet()) { } I'd like to compare entry and the next one after that. How would I do it? ...

Java Hashmap: Swap two values?

Can I swap the keys of two values of a Hashmap, or do I need to do something clever? Something that would look something like this: Map.Entry<Integer, String> prev = null; for (Map.Entry<Integer, String> entry: collection.entrySet()) { if (prev != null) { if (entry.isBefore(prev)) { entry.swapWith(prev) } } prev = ent...

Keys and terminology

I have a predicament related to terminology. Our system processes events. Events are dispatched to a node based on the value of some field (or set of fields). We call this set of fields the key. We call the value of that set of fields the key value. What adds confusion is that each event is essentially a bag of key-value pairs (i.e., a...

Does flex not support hashmaps?

I have a Flex object which collects a DTO from the server. All the fields arrive filled in correctly except for the one that is a HashMap. It arrives as null. I've tried giving it a type of both ArrayCollection and Dictionary, but that hasn't fixed it. Does anyone know if there's an inherent incomaptability between Java HashMap and Flex...

AV while iterating through hash_map?

_transaction is a private member variable of my class, declared as: public: typedef stdext::hash_map<wchar_t*, MyClass*, ltstr> transaction_hash_map; private: transaction_hash_map _transactions; During cleanup I am trying to iterate through this list and free up any objects still unfreed. However I am getting an AV on the for...

HashMap vs ArrayList performance am I correct

I currently believe that: When you need a structure from which you will be retrieving items randomly - use a HashMap When you will be retrieving items in order (e.g. using a for loop) - use an ArrayList Am I generally correct? Are there situations where this is not correct? ...

Memory overhead of Java HashMap compared to ArrayList

I am wondering what is the memory overhead of java HashMap compared to ArrayList? Update: I would like to improve the speed for searching for specific values of a big pack (6 Millions+) of identical objects. Thus, I am thinking about using one or several HashMap instead of using ArrayList. But I am wondering what is the overhead of Ha...