Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

store list of names in a variable

 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ....how to store list of names in a variable...show me a sample code
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi preethi Ayyappan,

I usually do it this way,the code goes like this

1. Import java utilities


2. Declare a Vector class object


3. Insert the name which you want to store


4. Declare a Enumerator


5. Then read values from the enumaration
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks bala....
 
Campbell Ritchie
Sheriff
Posts: 48409
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would usually be better off using java.util.ArrayList than Vector. And you are also better using the name of the interface List to declare the list rather than the class name.
And don't use variable names like newvct; call them something which a reader can understand.
 
Campbell Ritchie
Sheriff
Posts: 48409
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And to get the elements back use the for-each loop or an Iterator rather than an Enumeration.
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell Ritchie.
I figured out the difference between Vector and ArrayList

Anyone interested may visit this link to know more about the difference
JAVA FORUM
 
Campbell Ritchie
Sheriff
Posts: 48409
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Balasubramanian Chandrasekaran:
Thanks Campbell Ritchie.
I figured out the difference between Vector and ArrayList

Anyone interested may visit this link to know more about the difference
JAVA FORUM
Only too pleased to help. And well done tracking down the difference, but the posts on that Sun forum are much harder to understand than anything on JavaRanch
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Campbell,

After reading the differences between Vector class and ArrayList i can understand that it differs in the way of synchronization.
Synchronization is the only bottle neck in using Vector when compared to ArrayList or else more?
 
Adam Schaible
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a legacy List implementation - I would strongly suggest not using it for new code. I'd suggest using ArrayList as your "default" list implementation, and use other structures when it makes sense.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic