2012-11-28 43 views
1

我想創建一個應用程序,該應用程序使用例如-dMyProps=123(而不是參數(args))來接受屬性。我知道這些屬性是在地圖上。所以我會得到它使用。Java屬性地圖打印問題

public void getProperties() { 

map myMap = System.getProperties();  
myMap.get(); 
... 

如果有多個屬性,我該如何讀取它們並將它們全部打印出來?

System.out.println(whatever needs to printed here);

如果有人能幫助我,我覺得它必須在完成for循環或增強的for循環,但我不知道該怎麼辦。

回答

0

假設map myMap = System.getProperties();,mapjava.util.Map這實際上是不正確的。 System.getProperties();將返回一個Properties類對象;它可以根據您的requirement.As爲如來itreated:

Properties prop = System.getProperties();

Set<Object> set= prop.keySet();//Returns a Set view of the keys contained in this map.