Page 1 of 1

Arraylist

Posted: Sun Aug 06, 2017 2:26 am
by RRRRRR
Sir see->

public static void main(String[] args)
{
List<String>c=new ArrayList<String>();
c.add("123");
System.out.println(c);
System.out.println(c.get(1)); //Gives IndexOutOfBoundsException.
System.out.println(c.get(-1)); //Gives ArrayIndexOutOfBoundsException.
}

If going to negative index giving AIOOBoundsException but if going to Positive index then giving IndexOutOfBoundsException. Why??

Re: Arraylist

Posted: Tue Aug 08, 2017 12:27 am
by admin