-1

For eg:- my Properties file contains the following data: user=system
user=oracle user=xyz . And I write the following code:-

import java.util.*;  
import java.io.*;  
public class Test 
{ 
public static void main(String[] args)throws Exception

FileReader reader=new FileReader("db.properties");  

Properties p=new Properties();  
p.load(reader);  

System.out.println(p.getProperty("user"));  

}  
}  

The output I get is xyz.

How to get all the values as an output ?

Coder
  • 65
  • 1
  • 2
  • 8
  • Technically not possible, java.util. Properties extends HashTable, so two key with the same name(or duplicate key) not possible, Work around - `user=oracle,xyz` – Subhrajyoti Majumder Sep 07 '15 at 11:33

1 Answers1

1

An extension of Subhrajyoti's answer.

public List<String> getValues(String key) {
    String list = p.getProperty(key);
    return new ArrayList<String>(Arrays.asList(list.split(",")));
}
McNultyyy
  • 992
  • 7
  • 12