Strange behavior of a java.util.Vector

From: Konrad Den Ende (
Date: 01/25/04

Date: Sun, 25 Jan 2004 15:28:56 +0100

I'm not sure if i'm going mad or stupid but as far as i can rely
on my eyes, when i ADD an element to a Vector, it gets put on
ALL the position, instead of the last one. It's like if it rolls all
the way down the list leaving its footprints along the way.

I wrote, like:
import java.util.*;

public class Temp {
 public static void main (String[] arg) {
  Vector vec = new Vector ();
  String[] outPutLine = new String[3];
  String line;
  for (int k = 0; k < 4; k++) {
   for (int i = 0; i < outPutLine.length; i++)
    outPutLine[i] = "S(" + i + ";" + k + ")";
   vec.add (outPutLine);

   System.out.println ("outPutLine " + k + " is: \t\t" + outPutLine[0] +
"\t" + outPutLine[1] + "\t" + outPutLine[2]);
   System.out.println ("The result is:");

   String test = "";
   for (int i = 0; i < vec.size (); i++) {
      for (int j = 0; j < 3; j++)
       test += ((String[])vec.get (i))[j];
      test += "\n";
     System.out.println (test + "\n---------------------------------\n");

So, is it just me or is there funky with the output? Where did the
element S(0;0) go, for instance?!

May all spammers die an agonizing death; have no burial places;
their souls be chased by demons in Gehenna from one room to
another for all eternity and more.
Sleep - thing used by ineffective people
            as a substitute for coffee
Ambition - a poor excuse for not having
                 enough sense to be lazy

Relevant Pages

  • Re: Letter to US Sen. Byron Dorgan re unpaid overtime
    ... put them in stupid places. ... Programming is difficult (as you must surely appreciate, ... > strings will be in the range 1...1000 characters. ... impose an artificially small limit on string length." ...
  • Re: Opinions on this code please guys....
    ... to see if the string writes off the end of the buffer. ... there's no check for error (or even EOF) which is quite ... This is allso undefined behavior and stupid. ... Even the above is horrendously ineffiient and stupid. ...
  • Re: Can lines collection be used to assist me in automatically numbering lines?
    ... >string it means it returns a string. ... Do me a favor and stay out of my posts. ... fenton stupid in a public forum. ... believe what's really STUPID is to call a guy like him stupid. ...
  • Re: a dyeing query
    ... Those magnifying glasses on strings are not very handy. ... Also the string cuts in the back of your neck, and they are inclined to tip up. ... That type was my first magnifying glass and was discarded quickly. ... I ended up with the Mag Eyes which work very well because you can also look over the top to look in the distance or TV. ...
  • Re: I Need Help on Mouse Jumping Out of Box
    ... Now cross your eyes. ... It takes just a bit of practice, ... and put a string thru it and tape it to the back of you ears and pull the ... Put a small eye-screw into the mousetrap near the bait end. ...