Skip to content

Tag: hashmap

Hashmap using lists as a buffer

I need to create a hashmap that can store multiple values for one key, I know multimaps could do this but I also need to keep those value lists to a specific length. I need a each key to store a list of n values with those being the latest n values, i.e if i reached length n and I

How to iterate through ArrayList values of HashMap?

A question from a total newbie. Sorry. I have this customersOrders HashMap that takes String as keys and ArrayList<Double> as values. I need to find the total sum of orders for each customer and the maximum total sum in order to find the biggest customer. How do I manage to do that using just nested For loops and HashMap methods?

What is the purpose of placing a HashSet inside of a HashMap?

For example: private HashMap<Integer, HashSet> variableName; I understand that HashMap implements Map and doesn’t allow duplicate keys and HashSet implements Set and doesn’t allow for duplicate values, but what is the purpose of placing a HashSet inside of a HashMap? Do they not achieve similar tasks by themselves (though in different ways and with different performance)? What functionality does doing

HashMap element is removed when another HashMap name remove an element

appearList is a HashMap with fixed data. I do: Then, when I remove an element from randomPersonList, that element on appearList is also removed unexpectedly. I expect to keep appearList as original. Can anyone tell me why and how to correct my code? Answer makes randomPersonList the reference to the same object as appearList. So with both variables you are

Unboxing may produce Null Pointer Exception after checking if key exists in Map

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 actually in danger of running into a null pointer exception? My understanding is that .containsKey() check would prevent this from happening. Code snippet sample output: [{T143=1, T153=3, T141=1}] Answer Assuming nothing else is

Hashmap – returning key and setting it as value of an object

I have two CSV files, one “crimeUSA.csv” with the headers state, city, population etc. and one StatesAbbreviations with the headers states, abbrev . First I read the “crimeUSA.csv” file and create CityCrime objects. Instead of using the state in this file, I want to match it with the state in the StatesAbbreviations file and set the state as the appropriate