• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

vector in vector

 
peter brews
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
peter brews
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would that make ArrayList the wrong choice?
 
peter brews
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want a synchronized ArrayList you can call
Collections.synchronizedList (new ArrayList(...));
 
Sayed Ibrahim Hashimi
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eugene Kononov ,
Could you please send me some links where i can find documentation about EJB's. I am using stateless session ejb.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic