I'm making a Java project for the university. I need to add in a String list the first 5 values of a Map, but I can't seem to find a way to iterate over just 5 elements and not all the elements like using an Iterator
Basically I have a Map declared as follows: Map<String, Integer> infl_numbers = new HashMap<>();
I want to do something like this:
for (short i =0;i<5;i++){
// element = get i-th element of the Map
// list.add(element)
}
Can anyone help me?