This question was asked to me in Razorpay. I could not come up with a solution. Can anyone help me in writing Java code for this.
Object[] array = { 1, 2, new Object[]{ 3, 4, new Object[]{ 5 }, 6, 7 }, 8, 9, 10};
Answer should be:
Integer[] = {1,2,3,4,5,6,7,8,9,10};
i.e. all the Integer elements should be stored
What I did is
for(Object obj: array){
if(obj instanceof Integer) list.add((int)(obj));
}
Which results in -> 1,2,8,9,10. How do I add 3,4,5,6,7 inside list?