ArrayList setSize() not there (ensureCapacity() does not work here)

Hi All,

I am in a middle of a project and i discover that arraylist does not have any method similar to vector setSize(). Is this a bug, however i tried to use an alternative but this is throwing me an Error.Please Help.

import java.util.*;

class Demo

{

publicstaticvoid main(String[] args)

{

List <String>listOfCar;

listOfCar=new ArrayList<String>();

listOfCar.ensureCapacity(5);

}

}

and the Error Message is...

C:\program1\java_programs>javac Demo.java

Demo.java:9: cannot find symbol

symbol : method ensureCapacity(int)

location:interface java.util.List<java.lang.String>

listOfCar.ensureCapacity(5);

^

1 error

[1129 byte] By [Dell_javaa] at [2007-11-26 18:02:23]
# 1

ensureCapacity is a method of ArrayList but not of List. (That's because in other implementations of List, such as LinkedList, ensureCapacity doesn't make any sense.)

You can do this I believe:

((ArrayList) listOfCar).ensureCapacity(500);

Of course, there's probably no need to call ensureCapacity with such low numbers.

paulcwa at 2007-7-9 5:32:15 > top of Java-index,Java Essentials,Java Programming...