I try with a loop like that
// ArrayList tourists for (Tourist t : tourists) { if (t != null) { t.setId(idForm); } }
I played around with this and found out that trimToSize() seems to work. I am working on the Android platform so it might be different.