I have declared a new vector called v of type String with an initial capacity of 10 and increasing by 5 each tiem using the following:

Code :

Vector<String> v = new Vector<String>(10, 5);

I am then trying to use the add method to add a randome string as follows:

Code :

v.add(toString(random.nextInt(5000)));

I am getting the following error;

Code :

error: method toString in class Object cannot be applied to given types;

Why can't i do this? I would have thought it would just pass a random number as a String!

November 9th, 2011, 04:12 PM

copeg

Re: Why cant I use toString() with vector?

See the API for Object - the toString method contains no parameters and returns a String - you are attempting to call a toString(int val) method, which does not exist. Call toString on an object, not passing the object to the method: