Junior — Middle
Have you had experience using the HashMap data structure in your projects?
sobes.tech AI
Answer from AI
Yes, I used the HashMap data structure in Java to store key-value pairs with quick access by key.
HashMap implements a hash table, which provides an average time complexity close to O(1) for access, insertion, and deletion of elements.
Example of usage:
import java.util.HashMap;
HashMap<String, Integer> map = new HashMap<>();
map.put("apple", 3);
map.put("banana", 5);
int count = map.get("apple"); // returns 3
if (map.containsKey("banana")) {
System.out.println("Banana is in the map");
}
HashMap is useful when you need to efficiently store and quickly search data by key.