hashmap Questions

6

Solved

In Python, you can have key,value pairs in a dictionary where you can loop through them, as shown below: for k,v in d.iteritems(): print k,v Is there a way to do this with Java HashMaps?
Jumbala asked 1/7, 2010 at 12:6

2

Solved

After reading the documentation for LinkedHashMap (and having used it several times), I'm still not clear about one of its properties. Is the iteration order for a LinkedHashMap: the same as inser...
Dewittdewlap asked 14/1, 2013 at 20:27

4

Is it possible to implement a concurrent hash map purely in Kotlin (without Java dependency)? I am new to Kotlin and it looks like there is no obvious API available in kotlin.collections.
Pydna asked 2/11, 2020 at 21:49

1

Solved

I have overridden the hashCode and equals methods as below, and I want to understand the implementation of Map get method. public class Student{ String name; Student(String s){ this.name = s; ...
Aged asked 6/7, 2024 at 19:23

6

Solved

I have two String arrays. One having short name. // days short name String[] shortNames = {"SUN", "MON", "...", "SAT"}; The other having long name. // days long name String[] longNames = {"SUND...
Gehring asked 20/5, 2015 at 3:16

10

Solved

I already know how to do it the hard way and got it working - iterating over entries and swapping "manually". But i wonder if, like so many tasks, this one can be solved in a more elegant way. I h...
Expositor asked 14/12, 2010 at 7:55

7

What are the practical scenario for choosing among the linkedhashmap and hashmap? I have gone through working of each and come to the conclusion that linkedhashmap maintains the order of insertion ...
Greenlaw asked 29/10, 2014 at 5:7

2

Please take a look at my code: Object longL = 2548214; Map<String, Object> map = new HashMap<String, Object>(1); map.put("LongNumber", longL); List<Map<String, Object>> re...
Joline asked 17/3, 2019 at 7:56

11

In java if I am looping over the keySet() of a HashMap, how do I (inside the loop), get the numerical index of that key? Basically, as I loop through the map, I want to be able to get 0,1,2...I fi...
Sullins asked 21/4, 2010 at 19:49

5

Solved

I was reading about difference between Hashmap and Hashtable here: http://javarevisited.blogspot.sg/2010/10/difference-between-hashmap-and.html Can anyone throw some light on why it says following...
Loosejointed asked 4/2, 2013 at 13:5

9

According to the Go blog, Maps are not safe for concurrent use: it's not defined what happens when you read and write to them simultaneously. If you need to read from and write to a map from con...
Braille asked 22/3, 2016 at 23:35

10

Solved

I have tried to search on HashMap in Android, but getting problem: Consider this example: HashMap<String, String> meMap=new HashMap<String, String>(); meMap.put("Color1","Red"); meMap...
Falcate asked 6/8, 2010 at 9:10

10

Solved

I'm looking for a way to rename a Hashmap key, but i don't know if it's possible in Java.
Euratom asked 26/5, 2012 at 14:2

24

Use Case The use case is to convert an array of objects into a hash map based on string or function provided to evaluate and use as the key in the hash map and value as an object itself. A common c...
Melise asked 8/10, 2014 at 19:33

4

I don't see this approach avoid the collision. I think if the key.hashcode is larger than table.length, there will be collision. Updates: Actually I refer to the HashMap#hash in JDK 1.8, and was a...
Elfont asked 16/7, 2017 at 5:52

11

Solved

HashSet is based on HashMap. If we look at HashSet<E> implementation, everything is been managed under HashMap<E,Object>. <E> is used as a key of HashMap. And we know that Hash...
Bainbridge asked 9/8, 2011 at 7:14

5

Solved

Java 9 offers Map.of() feature to easily create a map with fixed values. Problem: I want to create a map that preserves order of insertion like LinkedHashMap. Is that possible with that factory? A...
Stalder asked 10/9, 2018 at 9:17

2

Solved

Android Studio gives the warning: Unboxing of 'idCollisonMap.get(currentId)' may produce 'NullPointerException' even though I am checking if the key exists before I perform the Map.get(). Am I actu...
Conroy asked 14/10, 2021 at 16:25

18

I have two HashMap objects defined like so: HashMap<String, Integer> map1 = new HashMap<String, Integer>(); HashMap<String, Integer> map2 = new HashMap<String, Integer>(); ...
Debility asked 28/11, 2010 at 23:23

12

Solved

Is checking for key existence in HashMap always necessary? I have a HashMap with say a 1000 entries and I am looking at improving the efficiency. If the HashMap is being accessed very frequently, ...
Balliett asked 2/9, 2010 at 11:45

4

Solved

HashSet is implemented using HashMap and when we add anything say e1 to HashSet, internally it adds (e1,new Object()) in the HashMap if e1 was not present in the set. My question is why they are in...
Hetaerism asked 4/5, 2015 at 18:48

4

Solved

I want to be able to convert a List to a HashMap where the key is the elementName and the values is a list of something random (in this case its the Element Name). So in short I want (A->List(A)...
Yaakov asked 23/7, 2014 at 17:27

6

Solved

Consider the following Code : import java.util.*; class Employee { String name; public Employee(String nm) { this.name=nm; } } public class HashMapKeyNullValue { Employee e1; public...
Ancestor asked 19/9, 2014 at 11:19

4

Solved

I am getting Cannot infer type arguments for java.util.HashMap<> for the following code class Test { public static void main(String[] args) { Map<Integer, String> map = new Ha...
Algebraist asked 23/11, 2017 at 7:17

3

Solved

I'd like to do the following: Lookup a Vec for a certain key, and store it for later use. If it doesn't exist, create an empty Vec for the key, but still keep it in the variable. How to do this...
Trinidadtrinitarian asked 14/2, 2015 at 4:23

© 2022 - 2025 — McMap. All rights reserved.