Sunday 15 March 2015

How to have a vector of integers in Java -


im trying to get a vector of integers using the following:

  Vector & lt; Int & gt; Vec = new vector & lt; Int & gt; ();   

But I get an error:

Syntax error on the token "int", the expected dimension after this token

I know that vector accepts objects only,

Is there an easy way of being a vector of an integer, without making such a thing?

Thanks

simply vector & lt; Integer & gt; Use .

Autoboxing lets you add integer s as they are int s

for example:

  vector & lt; Integer & gt; Vector = new vector & lt; & Gt; (); // diamonds are allowed in 7+ vector.add (5);   

In addition, you forgot to mention an instance name for your vector.

No comments:

Post a Comment