how to remove 1st value from a vector

Hi Folks!

Basically I am trying to remove 1st value in my Vector. also i need to store it in any

int variable. Can anydody tell me how can i do this please?

my vector is numberPackets

System.out.println("Vector packets..."+numberPackets);

Thanks alot in advance

[325 byte] By [asyed01a] at [2007-11-27 8:47:05]
# 1
Please read the Vector API, specifically about the various remove methods.
ChuckBinga at 2007-7-12 20:51:10 > top of Java-index,Java Essentials,New To Java...
# 2

> Hi Folks!

>

> Basically I am trying to remove 1st value in my

> Vector. also i need to store it in any

> int variable. Can anydody tell me how can i do this

> please?

>

>

> my vector is numberPackets

>

> > System.out.println("Vector

> packets..."+numberPackets);

> /code]

>

> Thanks alot in advance

if you know the first element you can remove it like this:

[code]

if (numberPackets.contains("text")){

numberPackets.get(0); // do something with the first element

numberPackets.remove(0);

}

deAppela at 2007-7-12 20:51:10 > top of Java-index,Java Essentials,New To Java...
# 3
I know there is a remove method but it need Object. Let say if i make object then how can i covert that object into int later.numberPackets.remove(0);but how i can save this value in an int.
asyed01a at 2007-7-12 20:51:10 > top of Java-index,Java Essentials,New To Java...
# 4
> I know there is a remove method but it need Object.No, it doesn't. http://java.sun.com/javase/6/docs/api/java/util/Vector.html#remove(int)~
yawmarka at 2007-7-12 20:51:10 > top of Java-index,Java Essentials,New To Java...
# 5

How do you store it in the vector, since Vector's cannot store primitives.

Vector v = new Vector();

int i = 1;

v.add(i); // will fail for jdk <= 1.4.2 // will auto box into Integer in 1.5 >

v.add(Integer.valueOf(i));//works in both

int b = ((Integer)v.remove(0)).intValue();//store the int value of the Integer at index 0 into b and removes it from the vector.

SomeoneElsea at 2007-7-12 20:51:10 > top of Java-index,Java Essentials,New To Java...