wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes store list of names in a variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "store list of names in a variable" Watch "store list of names in a variable" New topic
Author

store list of names in a variable

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
hi ....how to store list of names in a variable...show me a sample code
Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

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

Joined: Oct 04, 2007
Posts: 518
thanks bala....
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38334
    
  23
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

Joined: Oct 13, 2005
Posts: 38334
    
  23
And to get the elements back use the for-each loop or an Iterator rather than an Enumeration.
Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

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

Joined: Oct 13, 2005
Posts: 38334
    
  23
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

Joined: Nov 28, 2007
Posts: 215

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

Joined: Oct 04, 2007
Posts: 101
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: store list of names in a variable