2011-07-28 28 views
0

我有一个属性文件,谁拥有此格式:奇怪的使用显示java.util.Properties

toto=titi 
fofo=fifi 
coco=cici 
mama=momo 
dada=didi 

我有一个奇怪的显示,当我分析这个文件。这是我正在使用的代码:

Properties prop = new Properties(); 
String fileLocation = "C:/myProperties.properties"; 
prop.load(new FileInputStream(fileLocation)); 

Iterator<Object> it = prop.keySet().iterator(); 
int line = 0; 
while (it.hasNext()) 
{ 
     String propertyName = (String) it.next(); 
     if (propertyName.equals("coco")) 
     { 
      System.out.println("coco found at line : " + line); 
      break; 
     } 

     else if (propertyName.equals("titi")) 
     { 
      System.out.println("Titi found at line : " + line); 
      break; 
     } 

     line++; 
} 

你认为我会输出什么?

我会在你的答案后编辑问题。

谢谢。

+2

这是某种测验吗? – adarshr

+0

'coco found at line:2'? – jjnguy

+0

绝对不是。 –

回答

5

Properties对象由Map实现支持,因此不要依赖于属性的排序。如果您还有其他事情要报告为“奇怪”,请详细说明您的问题。 :-)

0

行号不相关,因为Properties使用散列来存储元素。订单不被保留。