Re: Vector Storing




"andrewzzz" <bugpezz@xxxxxxxxx> wrote in message
news:1170237968.812679.56480@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
In a class I have to store and mantain a Vector object.
I can declare it as static, but anyway to access it I have to
initialize the Vector (new Vector()) ... so everytime I create a new
instance of this class I lose my data(??).


actual :

private static Vector dynvector;


in the constructor :

dynvector=new Vector;
dynvector.add(de);//add de to the end of the vector


What should I do to save the content of a vector ???

It's totally unclear what you're trying to accomplish. The two main
possibilities are that you are trying to have each newly created object
(whatever your class stands for) register itself in a vector so that you can
know all of them OR each newly created object contains a list of things, one
of which is the parameter passed to the constructor. You have to first
figure out what you're trying to do. If it's the former, put the new vector
into a static block in the class--it will be initialized once when the class
is loaded. If it's the latter, remove the static keyword from the vector
declaration so that each object has its own list. If it's something else...

Matt Humphrey


.



Relevant Pages

  • Re: [Eclipse] How to fix indentations.
    ... Wouldn't it be better to initialize the list ... or else declare it as an instance variable ... because you put all the addcalls in the constructor instead of a static initializer. ... See Joshua Bloch's excellent book /Effective Java/ on preferring interfaces to concrete implementations for variable types. ...
    (comp.lang.java.help)
  • Re: Vector Storing
    ... andrewzzz wrote: ... I can declare it as static, but anyway to access it I have to ... initialize the Vector ) ... ... so everytime I create a new ...
    (comp.lang.java.programmer)
  • Re: Vector Storing
    ... I can declare it as static, but anyway to access it I have to ... initialize the Vector ) ... ... so everytime I create a new ... EveryTime the construcor of that class is called I have to append in ...
    (comp.lang.java.programmer)
  • Re: initialize array elements during declaration
    ... > function in an array when I declare it. ... > shall i initialize the elements in the array. ... same ones that A uses in its constructor. ...
    (comp.lang.java.programmer)
  • Re: Inherited Methods and such
    ... what I see in Initialize is ... Now, what you want is to get in the constructor of some S derived from T, ... The base types and registry are part of the framework and the user ... provides the concrete factories. ...
    (comp.lang.ada)