I read an .ini File and put every property into an temporary array which i put at the end into a vector – until here it works fine.
But if I want to access every array in that vector, I get ALWAYS the same results, which is impossible. I tried it with different ways, different loops and everything different, but always the same results, here is my actuall code:
tmp2 = new String[2];
for(Enumeration e=allPropertys.elements(); e.hasMoreElements();) {
tmp2 = (String[])e.nextElement();
for(int i = 0; i < tmp2.length; i++)
{
System.out.println(tmp2[i]);
}
}
And here is the code where I put everything into the vector:
try {
tmp = new String[2];
prop = new Properties();
prop.load(new FileReader("konfig.ini"));
Enumeration e = prop.propertyNames();
while (e.hasMoreElements()) {
String key = (String)e.nextElement();
String value = prop.getProperty( key );
tmp[0] = key + " " + value;
tmp[1] = value;
System.out.println("Property: " + tmp[0] + " und Value: " + tmp[1]);
allPropertys.add(tmp);
}
}
My guess is that when you populate your vector, you reuse the same string array for every property. This makes you vector contain 10 times (10 being the number of entries) the same array:
This should be replaced by
Also, note in your code snippet, you create a new String array to initialize your tmp2 variable, and then replace its value by the one in the vector. The initialization is unnecessary.