package com.snapfires.pdf;
public class FultonObj {
private String fileNo;
private String parcelId;
private String situs;
public String getFileNo() {
return fileNo;
}
public void setFileNo(String fileNo) {
this.fileNo = fileNo;
}
public String getParcelId() {
return parcelId;
}
public void setParcelId(String parcelId) {
this.parcelId = parcelId;
}
public String getSitus() {
return situs;
}
public void setSitus(String situs) {
this.situs = situs;
}
}
package com.snapfires.pdf;
import java.util.ArrayList;
public class List {
public static void main(String arg[]) {
ArrayList<FultonObj> list = new ArrayList<FultonObj>();
FultonObj fuOb = new FultonObj();
String file1 = "file#1";
String file2 = "file#2";
String file3 = "file#3";
String parcelId1 = "parcelId1";
String parcelId2 = "parcelId2";
String parcelId3 = "parcelId3";
String situs1 = "situs1";
String situs2 = "situs2";
String situs3 = "situs3";
fuOb.setFileNo(file1);
fuOb.setParcelId(parcelId1);
fuOb.setSitus(situs1);
list.add(fuOb);
fuOb.setFileNo(file2);
fuOb.setParcelId(parcelId2);
fuOb.setSitus(situs2);
list.add(fuOb);
fuOb.setFileNo(file3);
fuOb.setParcelId(parcelId3);
fuOb.setSitus(situs3);
list.add(fuOb);
for(int b=0; b<list.size(); b++) {
System.out.println(list.get(b).getFileNo());
System.out.println(list.get(b).getParcelId());
System.out.println(list.get(b).getSitus());
}
}
}
When I run this small program, I am only getting the last object that was added to the List. Although it iterates through the list but the result is that it prints out the last object that was added. e.g.
file#3
parcelId3
situs3
file#3
parcelId3
situs3
file#3
parcelId3
situs3
I want all the objects that were added to the List to be there not just the last object. Could someone let me know why this is not happening?
I don't think creating new FultonObj object each time will solve my issue. Here is why. I am reading a text file where it is possible that one line may have only file# and second line may only have file# and parcelId and third line may have file#, parcelId, situs. Or any combination of file#, parcelId, situs per line. However the order will always be same, meaning you will always have: file#, parcelId, situs. So I need to make sure that fuOb is complete before I add it to ArrayList. If I create multiple fuOb then it is possible that none of the fuOb will be complete, meaning it has file#, parcelId, situs.