lundi 20 avril 2015

ArrayList and Formatter not behaving as expected

I have two Arraylists, one contains an entire list of objects, the second contains objects to remove from the first list.

When I remove the objects from the first list and when I output those objects to a file using a Formatter, nothing is written to the file. However if I output the objects from the first Arraylist, without removing any objects, all of those objects appear in the file.

For example:-

for(Invoice inv : tempStore)
{
  if(invoiceLines.contains(inv))invoiceLines.remove(inv);
}

//for each invoice in the ArrayList
for(Invoice invoice : invoiceLines)
{
  output.format("%"+this.spec.getLength("XXXX")+"s\t",checkString(invoice.getInvoiceDate()));}

gives me no output, however doing just:-

//for each invoice in the ArrayList
for(Invoice invoice : invoiceLines)
{
  output.format("%"+this.spec.getLength("XXXX")+"s\t",checkString(invoice.getInvoiceDate()));}

gives me output information, when manually debugging the application the arraylist (the one with the objects removed), does contain objects still and those objects contain the correct values. It's almost as if the Arraylist, once objects are removed is losing the pointers in memory.

Any ideas? Unfortunately I can't give much in the way of specific code, however ask any questions and I will try to answer as best as I can. The language is Java and I'm using Java compliance 1.5 in the SDK.

Aucun commentaire:

Enregistrer un commentaire