Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing Externally values

 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some values ...which i wish to pass externally from a file to the program.

But there are repetitive param names for certain values..

Suppose,

Field1=value1
Field1=value2
Field1=value3

What is the best strategy if i want to handle these kind of values..??

I tried using properties but it wont allow duplicate keys..

Regards
 
Nupur Gupta
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try creating an object with all the params!
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try creating an object with all the params


What type of an object are you referring to ???
 
Nupur Gupta
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any object that encapsulates all the features. If you want to know more about objects, read any basic book on java.
 
Srikanth Ramu
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the values are in a file in the above given format, then you need to parse the file using StringTokenizer.

You could either store them in Key-Values structure or have your own object structure like setKey(key), setValues(valueList).
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Property files are out because of duplicate keys, but you can make files that look the same and parse them yourself. Srikanth's tip about StringTokenizer was a good start.

See if this multimap example gives you some ideas about storing multiple values for one key.
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Srikanth and Stan... i will try to proceed with this...
[ April 06, 2007: Message edited by: A Kumar ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic