ArrayList(int initialCapacity) ==> why initial capacity not present ?

Hi,

I'm trying to create an ArrayList of initial size 5, and later on to set the first entry to a value :

List TrList =new ArrayList(5);

System.out.println(TrList.size());

TrList.set(0,4);

System.out.println(TrList.get(0));

When I run this I get :

0

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

at java.util.ArrayList.RangeCheck(ArrayList.java:547)

at java.util.ArrayList.set(ArrayList.java:337)

at vampstatistics.TransactionFileHandler.ReadGlobalDataAndWriteToFile(Main.java:58)

at vampstatistics.Main.main(Main.java:249)

Java Result: 1

[697 byte] By [JohanDa] at [2007-11-26 15:10:28]
# 1
You cannot set the lists size. The parameter you give is the initial capacity being used for the underlying implementation to preoccupy some space.
stefan.schulza at 2007-7-8 9:01:18 > top of Java-index,Core,Core APIs...
# 2
The English word "capacity" refers to how much an object CAN hold, not how much it DOES hold. So an empty jug could have a 2-litre capacity, meaning that it could hold 2 litres of water.
DrClapa at 2007-7-8 9:01:18 > top of Java-index,Core,Core APIs...
# 3
thanks a lot
JohanDa at 2007-7-8 9:01:18 > top of Java-index,Core,Core APIs...