使用java.util.Properties进行奇怪的显示

Was*_*RAR 0 java iterator properties fileinputstream

我有一个.properties文件,其格式如下:

toto=titi
fofo=fifi
coco=cici
mama=momo
dada=didi
Run Code Online (Sandbox Code Playgroud)

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

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++;
}
Run Code Online (Sandbox Code Playgroud)

您认为我将在输出中拥有什么?

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

谢谢.

San*_*rma 5

Propertiesobject由Map实现支持,因此不要依赖于属性的排序.如果您还有别的东西要报告为"奇怪",请详细说明您的问题.:-)