Junior — Middle
Have you used the Map data structure in Java development?
sobes.tech AI
Answer from AI
Yes, the Map data structure in Java is widely used for storing key-value pairs. For example, HashMap allows quick retrieval of values by key. This is convenient when you need to organize fast searches or group data.
Example of using HashMap:
import java.util.HashMap;
import java.util.Map;
public class Example {
public static void main(String[] args) {
Map<String, Integer> map = new HashMap<>();
map.put("apple", 3);
map.put("banana", 5);
System.out.println("Number of apples: " + map.get("apple"));
}
}