This happens, because your list has one element (Size:1
), and you ask for the second element (Index:1
- Indexing starts from zero)! A simple System.out.println
for each list element will help you get through...
Why do you set the number of elements to 3? If you know that it will be 3 (unlikely), then change the list to an array of size 3. If you don't know that, then change num
to list.size()
, like:
for(int i=0;i<list.size();i++)
But before anything else, you should understand why you get these values for this key.