Most voted "hashmap" questions
A data structure that uses a hash function to map identification values, known as keys, to their associated values.
Learn more…68 questions
Sort by count of
-
37
votes5
answers22775
viewsWhat is the best way to iterate objects on a Hashmap?
What is the best way to iterate objects into one HashMap in Java to gain access to the key and value of each entry?
-
11
votes2
answers6730
viewsHow does the hash table implementation work?
The concept of hashes (or tables hash) is already embedded in various programming languages such as Javascript, Python, Ruby, etc., and is known to be much faster than, for example, chained lists.…
-
11
votes1
answer255
viewsCanonicalized Mapping and Weakreference
I would like someone to explain the concept (and applications) of Canonicalizing Mapping and how your reference implementation would work using Weakhashmap.…
java performance memory-management hashmap garbage-collectorasked 9 years, 5 months ago Reginaldo Soares 2,256 -
9
votes1
answer1858
viewsWhat are the differences between Hashmap and Hashtable?
What are the differences between HashMap and Hashtable in Java? Which is more efficient?
-
8
votes1
answer725
viewsDifference between Hashmap and Treemap
What are the main differences between HashMap and TreeMap? Regarding use, in which situations it is recommended to use each one?
-
6
votes1
answer1411
viewsHow to place variables within vectors?
How do I create variables within a vector? Something like: int arr[] = {int x=1, int y = 2};
-
6
votes2
answers959
viewsHow to compare the value of a Hashmap<key, value> with a variable?
I have a HashMap aluno<Integer, Float>, where the key Integer will be the student’s registration number, and the amount Float will be the student’s grade. I got the grade average using the…
-
5
votes1
answer727
viewsHow to create a value pair within a Java Map
It is possible to create a Map in Java using the concept of pair that exists in C++? I have tried to use it in the form below, however, I cannot assign values to my map. Map<String,…
-
5
votes1
answer259
viewsWhy not iterate a hashmap?
I was doing a project and one of my colleagues mentioned that iterate hashmaps is something to avoid and instead of using hashmap should wear Linked lists. However I think the versatility of the…
-
5
votes1
answer1139
viewsHashmap manipulation between classes (Interpretation and Application)
is my first question, sorry for the length, I am in doubt in the following exercise: Create a Pizza class that has the added method Cooking() that receives a String with the ingredient to be added.…
-
4
votes1
answer2157
viewsDifference hashmap and arraylist
Could someone explain to me the difference between HashMapand ArrayList?
-
4
votes1
answer630
viewsHow to use a counter inside a Hashmap?
It is possible to do this? public static void main(String[] args) { Scanner in = new Scanner (System.in); Map <String,Integer> mapa = new HashMap <String,Integer>(); mapa.put("45 - Jose"…
-
4
votes1
answer88
viewsSparsearray vs Hashmap what’s the difference?
I was doing my daily refactoring and came across a warning. use new Sparsearray(...) to Instead for Better performance Okay, but what’s the difference between Map and SparseArray? This is my code:…
-
3
votes3
answers2230
viewsJava shows "Type Safety: Unchecked cast from Object to Hashmap"
I’m creating a class that through that works similar to Xpath. The function works perfectly, the problem is that in this part of the line (HashMap<String, Object>) test.get("test-map");,…
-
3
votes4
answers3125
viewsDealing with collisions in Dictionary C#
I need to map a string array to a dictionary so that I can later test whether an informed string is valid by checking if it is part of the dict, additionally would like to recover some other…
-
3
votes1
answer704
viewsScatter table (Hash Tables)
I have a hash table closed with open addressing and linear scanning for the following dictionary of words, from a text; The input operation works like this: 1) The program asks for the first line of…
-
3
votes1
answer88
viewsError returning Hashmap to Javascript
When returning the hashmap to javascript I got the following error: The Resource identified by this request is only capable of generating Sponses with Characteristics not acceptable According to the…
-
3
votes1
answer156
viewsmap.foreach Unexpected Return value
I have the following map: private static Map<ParseCreator, Parseable> map = new HashMap<>(); I walk this map as follows: for (Map.Entry<ParseCreator, Parseable> entry :…
-
3
votes1
answer40
viewsJava: Convert point-delimited strings to nested JSON
I have a lot of attributes coming as point-delimited strings like "company.id", "company.address.number", "user.name", "isAtive", and I need to create a nested JSON with its respective values. These…
-
2
votes1
answer315
viewsCollection Map<k,v> Methods
Doubts about the methods replace : compute : computeIfAbsent : computeIfPresent :forEach(briefly all who make use of the function or biFuntion within the input parameter) The replace is it really…
-
2
votes2
answers1417
viewsHigher frequency of a string
I have a text where I am treating several things. Now I need to get the 3 words that are most repeated in the entire text. How can I do this? What is the best solution? I thought about storing in a…
-
2
votes1
answer158
viewsStore <Integer,Integer,Arraylist<Integer>> in a collection
What I intend to do is make a data association as follows: (<<Integer>, <Integer>, ArrayList<Integer>) I tried to create a…
-
2
votes2
answers3012
viewsHow to go through the values of a Hashmap through a certain key?
How can I traverse the values of a Hashmap through a certain key? An example to illustrate: I have a Hashmap called values, with a key that is an id represented by String and a value that is an…
-
2
votes1
answer1430
viewsHow to add element inside an arrayList that is inside another Arraylist that in turn is inside a Hashmap?
The question is: I have the Classes Student, Discipline, Grade, Class. I need to add a double value in an Arraylist that is in an object of the Discipline class, but the Discipline class is inside…
-
2
votes1
answer194
viewsDifference between Std::map, Std::unordered_map, Std::flat_map, and which one to choose?
What is the difference between library functions map, unordered_map, flat_map, and which one to use, for example in terms of performance?
-
2
votes1
answer104
viewsMapping active and disconnecting users to exceed 3 users
I wonder how I could map the users who connect based on their unique id’s and id session so that when there are more than 3 sessions for that id, the users who connected first are removed from the…
-
2
votes2
answers1661
viewsHow to sort a Map by key in Java
I’m trying to use a loop to show the grouped information of a Map. for(Map.Entry<Date, List<Exam>> entry : groupedList.entrySet()) { setNewList(entry.getKey(), entry.getValue()); } But…
-
1
votes1
answer611
viewsHow to access data from a Hashmap in another class
How can I access data from a Hashmap in another class? Example: Class1: Hashmap<String,String> teste = new Hashmap<>(); teste.put("TESTE", "exemplo"); Class2: How can I access Hashmap…
-
1
votes1
answer1595
viewsBrowse Hashmap<Integer, Hashmap<Integer, Arraylist<Integer>>
I got the following HashMap: HashMap<Integer,HashMap<Integer,ArrayList<Integer>>> hm = new HashMap<>(); When I do this: Set<Integer> keys = hm.keySet(); for(int i :…
-
1
votes1
answer577
viewsHow to find the value of a hashmap element?
I have a very strange doubt, I have a HashMap that has these two values ids("pergunta","IdP"); To pergunta is a String and IdP is a Int, me now to get the value of Idp I have to do int a =…
-
1
votes0
answers188
viewsArraylist<Hashmap<String, String>> in a Base Class
I have the following Arraylist: ArrayList<HashMap<String, String>> menuItens = new ArrayList<HashMap<String, String>>(); for (int i = 0; i < 6; i++){…
-
1
votes2
answers726
viewsHow to use Hashmap in this case?
I’m a beginner in Java. I need a program that reads the name and number of some people and then type a number and the program returns the name of the person associated with the number. I was…
-
1
votes0
answers105
viewsProblem with List and Hashmap
I have a list as stated below: List<Map<String, String>> lista = new ArrayList<Map<String, String>>(); Map as declared below: Map<String, String> mapa = new…
-
1
votes1
answer542
viewsGiven a list of words, return the size of each descending anagram group
I have a file with a list of words, each in a line of the txt. I need to group those that are anagrams and return the size of the group, in descending order. Follow an example: cat, bed, aeds, drop,…
-
1
votes1
answer475
viewsHow to show Hashmap value?
I’m having trouble showing (can be using a for) the value of this Hashmap. Does anyone know how? The console only shows this value: {Joao=[Ljava.lang.String;@2b05039f} I can’t show the internal…
-
1
votes1
answer111
viewsCheck if position is between 2 positions
I am using this code here to check if a position is 'inside' an 'area', but it will probably explode if the hashmap has many Keys/Values, what would be the best way to do this ? Thank you.…
-
1
votes1
answer209
viewsHow to create a custom filter in the android lestview that searches for words after the space character
In this code the filter is working until the first word. From the moment I enter the space character the filter stops working. Example: Search "Steve Jobs", the system gets lost. Now if you search…
-
1
votes2
answers658
viewsWhat is a Python hash map?
I’m a beginner in Python, and I’m doing an exercise that says the following: Considering a string, "We will keep a hash map (set) to track the unique characters we find. Footsteps: Scan each…
-
1
votes1
answer750
viewsMethod Returning Empty List
I am having a problem with a java method. The intention is to split a Hashmap into pages, and return an Arraylist with each page. Code: public static ArrayList<HashMap<String, Key>>…
-
1
votes1
answer92
viewsProblems with hashmap getordefault in java
I have a hashmap problem, in JAVA. I’m trying to create a program that reads data from a car, save these cars in an Arraylist and organize, by the manufacturer(that would be the key) the cars of…
-
1
votes1
answer345
viewsIs Hashmap possible with various values?
I need to fill a bank like this: Milk 50 kcal 20 proteins 120 Carbo etc. I got to do with hashmap, but I can only use one key for a value, it would have to do with various values, or another way…
-
1
votes1
answer688
viewsExercise with Hashmap
I’m trying to do this exercise, I don’t know where I’m going wrong. Can you help me? I need to create a map that has the number of characters of a city name and by value in a list of all names with…
-
1
votes1
answer109
viewsDisplay higher word frequency per line and calculate number of words per line
I have the following text and I have to display the words that appear most frequently per line and calculate the amount of words each line This is a really really really cool experiment really Cute…
-
1
votes0
answers69
viewsCompare two hashmaps
Hello, I need to buy the values of 2 Hashmaps. I’m making an Image Matcher using equal amount of colors, using this code, but I don’t know how I can compare them. public static double…
-
1
votes4
answers141
viewsIs there performance gain using . replace() instead of . put() in a Map?
Is there any performance gain using the method .replace() instead of using .put() in a Map. Studying Maps I noticed that the method .put() and .replace() have practically the same function. I made a…
-
1
votes1
answer560
viewsMap returning repeated values
I’m making a foreach in a hashmap on the basis of the following arquivo.txt: chaveA;6 chaveA;4 chaveB;3 chaveB;7 chaveC;1 chaveC;1 chaveD;5 For now my code is like this: Scanner scanArquivo = new…
-
0
votes1
answer458
viewsHow to browse Hashmap with subkeys?
How to walk a HashMap who owns another HashMap? for (Map.Entry<Date,HashMap<String, Integer>> entrada : m.entrySet()) { // .... }…
-
0
votes0
answers71
viewsHash Table for text word incidence
This problem was best illustrated here: Error in vector copy of structured type Summary: I am developing an index dictionary, which stores the incidence of a word of text (input) using a hash table…
-
0
votes1
answer592
viewsOperations with Hashmap
Good afternoon guys, I need to do some operations using Hashmap. I am new in the area. I have the following map protected Map<String, Map<String, Integer>> elementos = new…
-
0
votes2
answers66
viewsUsing a map to store 1 ID for N values?
EDIT for lack of details, I have answered the question here. The question has been flagged and a moderator will delete it as soon as possible, thank you. I have the following Ids and values…