my dog learned polymorphism*
The moose likes Java in General and the fly likes vector in vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "vector in vector" Watch "vector in vector" New topic
Author

vector in vector

peter brews
Ranch Hand

Joined: Jan 25, 2002
Posts: 59
Dear All,
I have vector of vectors
Vector VMaster - [[flag, 0,1,1], [state, NJ,NY,ALL],[f1,11,12],[f2,22,24,80,09]]
I need to replace some of the elements of this vector with new value.
For ex.
I need to replace
[flag,0,1,1] to [flag,false,true,true]
and
[state ,NJ,NY,ALL] to [state,newjersey,newyork,ALL]
so that the final vector should be like
[[flag,false,true,true], [state,newjersey,newyork,ALL] ,[f1,11,12],[f2,22,24,80,09]]
What changes should I make to following code:
can I use SetElementAt()

for (int i = 0; i < VMaster.size(); ++i) {
Vector subVect = (Vector) VMaster.elementAt(i);
String field1 = (String) subVect.elementAt(0);

for (int j = 0; j < subVect.size() - 1; ++j) {
if(field.equals("flag"))
{���.
����.
}
Thanks,
ag
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Are you sure you want to use Vector? If these vectors are all fixed size, arrays would be a better choice. If not, ArrayList (from the Collections framework) is now preferred.


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
peter brews
Ranch Hand

Joined: Jan 25, 2002
Posts: 59
i want to use vector because the size is dynamic.
Can't use arraylist ,as this is a part of code from the utility method in my ejb
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Why would that make ArrayList the wrong choice?
peter brews
Ranch Hand

Joined: Jan 25, 2002
Posts: 59
i think there may be synronization problem.
I do wanted to post sevearl question regrding the utility methods that i have in my ejb.
like changeDateFormat method,databaseconnection utilty method,formatdata utility method.
I was thinking of using methods as private static
or private (without static) will be a better choice .
several other methods will be calling these methods to format the data in desired format before returing to the client.
Please explain what wil be better choice memory and time wise
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
If you want a synchronized ArrayList you can call
Collections.synchronizedList (new ArrayList(...));
Sayed Ibrahim Hashimi
Ranch Hand

Joined: May 17, 2001
Posts: 148
Originally posted by Ron Newman:
If you want a synchronized ArrayList you can call
Collections.synchronizedList (new ArrayList(...));

Ron-
So if you have a synchronized ArrayList then why would that be much better than using a Vector? Isn't that the main difference between ArrayList and Vector, that Vector is synchronized and by default ArrayList isn't?
Do you know of any performance benefits of using a synchronized ArrayList vs. a Vector?
Thanks.


SCJP 1.4<br /><a href="http://www.cise.ufl.edu/~sih" target="_blank" rel="nofollow">www.cise.ufl.edu/~sih</a>
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Vector has been retrofitted to implement List but is still carries old methods such as addElement. Since the Vector gives you nothing that a sysncronized List can give you, stick with the newer List objects.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

i think there may be synronization problem.

I think you mentioned that your code is in EJB. If so, don't worry about synchronization. By the spec, the EJBs are single threaded, and therefrore using synchronized data structures (such as Vector) would be an unnecessary overhead.
Eugene.
peter brews
Ranch Hand

Joined: Jan 25, 2002
Posts: 59
Eugene Kononov ,
Could you please send me some links where i can find documentation about EJB's. I am using stateless session ejb.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: vector in vector
 
Similar Threads
prime number problem
DefaultTableModel and Vector
XML Node Parsing Problem , when Node owns NodeList using Xercer , HELP !!!!
replace elements in vector in jdk 1.3.1
which break statement doulh I use