0

Possible Duplicate:
What's the most elegant way to concatenate a list of values with delimiter in Java?

I have 3 different words listed in property file in 3 different lines. QWERT POLICE MATTER

I want to read that property file and store those 3 words in String, not in aarylist separated by whitespace. The output should look like this String str = { QWERT POLICE MATTER}

Now I used the follwoing code and getting the output without white space in between the words: String str = {QWERTPOLICEMATTER}. What should I do to the code to get the string result with words separated by whitespace.

FileInputStream in = new FileInputStream("abc.properties");
            pro.load(in);
            Enumeration em = pro.keys();
            StringBuffer stringBuffer = new StringBuffer();
            while (em.hasMoreElements()){
               String str = (String)em.nextElement();
               search = (stringBuffer.append(pro.get(str)).toString());
Community
  • 1
  • 1
xyz
  • 1

2 Answers2

0

Try:

search = (stringBuffer.append(" ").append(pro.get(str)).toString());
Jean Logeart
  • 52,687
  • 11
  • 83
  • 118
0

Just append a blank space in your loop. See the extra append below:

while (em.hasMoreElements()){
    String str = (String)em.nextElement();
    search = (stringBuffer.append(pro.get(str)).toString());
    if(em.hasNext()){
        stringBuffer.append(" ")
    }
}
Russell Shingleton
  • 3,176
  • 1
  • 21
  • 29