Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Values in a Properties File

 
Ranch Hand
Posts: 225
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a properties file in my Java application and I would like to have the property, event.name.alias, contain multiple values.

Would this be correct?

event.name.alias=myname1, myname2
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A java.util.Property always has a single value. If you want to interpret that value as multiple values separated by commas, you can, but you'll have to provide the code to split the single String up into multiple values based on your rules.
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Fred Victa wrote:I have a properties file in my Java application and I would like to have the property, event.name.alias, contain multiple values.

Would this be correct?

event.name.alias=myname1, myname2



No you can't, it will return the string with commas inside.

Please think about using an xml...

D.
 
Marshal
Posts: 67446
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
XML? Overkill for this simple requirement.
 
Daniel Val
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:XML? Overkill for this simple requirement.



True.

you can do like that

val_1=value for the first
val_2=value for teh second etc

Then you load the properties, then you get the iterator for the keys, then if the key "startsWith" val you get the value and add it to the list.

It works fine, but ensure you don't put by mistake a duplicate key val_something.

D
 
    Bookmark Topic Watch Topic
  • New Topic