There is a HashMap<String, String> required to run through it getting the name, value. But run through the indices of 56 to 70, in the case of going beyond the limits to issue an exception.
Closed due to the fact that the essence of the question is unclear by the participants user194374, insolor , Abyx , D-side , VenZell Mar 28 '16 at 9:51 .
Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .
1 answer
There are two problems: HashMap does not support indexed access, and also does not guarantee the return of records in the same order in which they were added. Therefore, reading certain indices does not make much sense.
At the same time, there is a LinkedHashMap , which guarantees the order of entries, but still does not have indexed access. Therefore, it is necessary to iterate the entire collection, at the same time keeping a record of the number of elements traversed and checking whether the collection has completed. Try to write this code yourself, if there are difficulties, update the question.
HashMapbasically does not guarantee order, and it’s strange to talk about indices in it. - zRrr