Java Properties Verstaendnisfrage

akira1974

Grünschnabel
Hallo,

ich beschaeftige mich das erste mal mit Java Properties und habe eine Frage dahingehend. Ich habe ein kleines Programm erstellt. In dem Programm sind 10 Buttons deren Bezeichnungen in den Properties gespeichert werden und zusaetzlich ein zweiter Wert pro Button. Es klappt alles ausgezeichnet. Ich habe nur die Frage wenn ich mit dem u. a. Code die Properties speicher, sind diese nicht in der Reihenfolge gespeichert wie in dem Code-Beispiel sondern wie folgt:

Code:
#Fri Feb 10 11:27:55 GMT 2012
bn10=Button 10 Name
bp9=Wert Button 9
bp8=Wert Button 8
bp7=Wert Button 7
bp6=Wert Button 6
bp10=Wert Button 10
bp5=Wert Button 5
bp4=Wert Button 4
bp3=Wert Button 3
bp2=Wert Button 2
bp1=Wert Button 1
bn9=Button 9 Name
bn8=Button 8 Name
bn7=Button 7 Name
bn6=Button 6 Name
bn5=Button 5 Name
bn4=Button 4 Name
bn3=Button 3 Name
bn2=Button 2 Name
bn1=Button 1 Name

Kann mir jemand erklaeren woran das liegt?

Java:
      try {
        //set the properties value
        propButton.setProperty("bn1",bn1);
        propButton.setProperty("bn2",bn2);
        propButton.setProperty("bn3",bn3);
        propButton.setProperty("bn4",bn4);
        propButton.setProperty("bn5",bn5);
        propButton.setProperty("bn6",bn6);
        propButton.setProperty("bn7",bn7);
        propButton.setProperty("bn8",bn8);
        propButton.setProperty("bn9",bn9);
        propButton.setProperty("bn10",bn10);
        
        propButton.setProperty("bp1",bp1);
        propButton.setProperty("bp2",bp2);
        propButton.setProperty("bp3",bp3);
        propButton.setProperty("bp4",bp4);
        propButton.setProperty("bp5",bp5);
        propButton.setProperty("bp6",bp6);
        propButton.setProperty("bp7",bp7);
        propButton.setProperty("bp8",bp8);
        propButton.setProperty("bp9",bp9);
        propButton.setProperty("bp10",bp10);

        //save properties to project root folder
        propButton.store(new FileOutputStream("properties/button.properties"), null);

      } catch (IOException ex) {
        ex.printStackTrace();
        }
 
Zuletzt bearbeitet:
Hi,

ich tippe mal darauf, dass das propButton intern mit einer HashMap arbeitet. Beim auslesen der Hashmap (quasi beim Speichern) sind die Elemente da drin nicht mehr in der Reihenfolge, wie du sie einfügst.

Zitat aus der Dokumentation der HashMap:
This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.

Gruß,
BK
 
Zuletzt bearbeitet:
Zurück