So I am having trouble trying to loop through an array list but i dont want to use a println statement to print the elements from the array list. Is it possible if i could store all the elements into a local variable through each loop and then return the local variable when i call the method later on?e Here is my code:
public String displayProperties() {
String property = null;
for (int i = 0; i < properties.size(); i++) {
property = properties.get(i);
}
return property;
}
java.util.Propertiesextendsjava.util.Hashtableand hence has no predictable order for keys. So there is no such thing a "last element".propertiesalready contains those elements and you can already get a certain property with yourproperties.get(i). What purpose do you had in mind wanting to store all values inpropertiesin a separated local variable? Some additional questions: where are they coming from (if they come from a.propertiesfiles there are loads of libraries to directly insert each property in a separated variable through annotations); what do you want to use them for; etc.