I'm currently working on Java Collection Framework , and created a list of size 10 still the program prompting me that the list size is 0, further if list processed it throws IndexOfBoundException of course
I've searched about this but I don't know why it's happening to me
int size =sc.nextInt();
List<Integer> list = new ArrayList<Integer>(size);
System.out.println(list+" "+list.size());
I expect the output as [0,0,0,0,0,0,0,0,0,0] 10 but output is [] 0 .
ArrayListwith initial capacity not sizeArrayList(int)does not "fill" the underlying buffer, it simple allocates the size buffer -ArrayListis backed by an array, so it takes time to resize, providing a initial buffer can help performance