Goldman Sachs Interview Question
Software Engineer / DevelopersHashMap is an subclass of the Map collection - in java. a HashMap uses a hash function to effciently map certian identifiers or keys to associated values. Map and HashMap have a (key, value) pair where the key is the custom index and the value is the object to store. To add an element to the HasHMap you call the method .put(key, value). in the put() method inside the code a hashfunction hashcode the key into an index. to retrieve something from a HashMap you use the method .get(key) to get a single index. HashMaps can contain null values and duplicates. HashMaps are vulnerable to collisions due to the custom indexing and being able to duplicate
java implementation
HashMap<Object>() map1 = new HashMap<Object>();
I believe the interviewer is looking out for a more detail answer, including how hashcode is used and what happens when there is a hash collision
- Anonymous August 08, 2010