• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Values in a Properties File

 
Ranch Hand
Posts: 226
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67682
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
XML? Overkill for this simple requirement.
 
Daniel Val
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
The longest recorded flight time of a chicken is 13 seconds. But that was done without this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic