This line
System.out.println(ages[1].intValue());
is incorrect. ages
is exactly one element. It should be
System.out.println(ages[0].intValue());
with no other changes I get
tony
50
70
To get 60
, you would need to print the second element of oldAge
. Like,
System.out.println(oldAge[1]);
solved How to solve ArrayIndexOutOfBoundsException error on trying to print appended object in an array? [duplicate]