We help IT Professionals succeed at work.

RemoveFirst J2ME

bachra04
bachra04 asked
on
I have the following code in Java :

MyPacket = MsgQueue.removeFirst();

MsgQueue is a list I want to mimic the same behaviour in J2ME using a Vector:

Is there a way to do that ?
Comment
Watch Question

Awarded 2011
Awarded 2011

Commented:
I guess you can say remove(0) fro a Vector

Author

Commented:
Not exactly :

 * This method removes first element of List and shifts the subsequent
     * elements to the left. It returns the element previously at the first index
     * of the  List.
Awarded 2011
Awarded 2011

Commented:
public Object removeFirst() {
Object ob = v.elementAt(0);
v.remove(0);
return ob;

}


remove(0) will also change indexes odf all subsequent emelements:

http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Vector.html#remove%28int%29
Awarded 2011
Awarded 2011
Commented:
so I don't know if you use Vector as association - so you create wrapper
around vector - then the method above with v representing Vector is fine
If you extend Vector then
you just use

Object ob = this.elementAt(0);
this.remove(0);

instead of v

Explore More ContentExplore courses, solutions, and other research materials related to this topic.