Vector Question for Newbie

From: Paul P (
Date: 12/30/03

Date: 30 Dec 2003 08:11:12 -0800


I am running into a very unusual problem when adding elements to a
vector. I'm using a Vector to accumulate messages for particular
datasets. There is one point where I have to add three messages to
the Vector at one time.

After adding the first one, Vector[0] has the entry just added.

After adding the second one, Vector[0] and Vector[1] both have the
entry just added (the second entry).

After adding the third one, Vector[0], Vector[1] and Vector[2] all
have the entry just added (the third entry).

I don't know why this is happening.

I tried to replicate this problem in some test code and was not able
to. The test code works as I would expect it to. The code is as

=====CODE BEGIN==============================================================
if ( ISArec.length() != 106 )
   cm = new CommMessages( "SplitX12File: (Second) ISA read failed for
" +
                          cc.SYS_IOEXCEPTION );
   cui.messages.add( nextMsgPos++, cm );
   cm2 = new CommMessages("ISArec=" + ISArec, "A", 0 );
   cui.messages.add( nextMsgPos++, cm2 );
   cm3 = new CommMessages("ISArec length=" + ISArec.length(), "B", 0
   cui.messages.add( nextMsgPos++, cm3 );
=====CODE END================================================================

The field "nextMsgPos" is initially loaded with the size of the
Vector. This gives the next position where an object should be added.

The results of the code are here (I added some linespacing to make it
more readable):

=====OUTPUT BEGIN==============================================================
[CommMessages[SplitX12File: (Second) ISA read failed for

[CommMessages[ISArec=, A, 0], CommMessages[ISArec=, A, 0]]

[CommMessages[ISArec length=0, B, 0], CommMessages[ISArec length=0, B,
0], CommM
essages[ISArec length=0, B, 0]]
=====OUTPUT END================================================================

The vector is defined as

    public Vector messages;

and then instantiated with

    messages = new Vector();

I am relatively new to Java programming in general and Vectors in
particular. What I'm trying to do seems to be relatively
straightforward. It's just not doing what I expect. I imagine it's
some trivial little thing I'm missing, but I'm stumped. Any help
would be greatly appreciated.