How do I create an object with an arraylist
and then when I clear the arraylist
I want the value to still be inside the object.
for (int i = 0; i < attribute.getLength(); i++) {
String current = attribute.item(i).getTextContent();
if(current.equals("Identifier")){
String hyperlink = list.get(count).hyperlink;
String title = list.get(count).title;
String identifier = list.get(count).identifier;
ItemAndAttributeObject object = new ItemAndAttributeObject(hyperlink, identifier, title, attributeList);
objectList.add(object);
count++;
attributeList.clear();
}
else{
attributeList.add(current);
}
}
When I run this code all the ItemAndAttributeObject
attributes are empty. How do I keep the value in the objects?
This is how my class, creating the objects looks like
public class ItemAndAttributeObject {
String hyperlink;
String identifier;
String title;
ArrayList<String> attributes;
public ItemAndAttributeObject(String hyperlink, String identifier, String title, ArrayList<String> attributes) {
this.hyperlink = hyperlink;
this.identifier = identifier;
this.title = title;
this.attributes = attributes;
}
}
I want is to create an object with an arraylist
of values and then clear the array for the next iteration in the loop.