What you want to see is class ArrayList.
This is basically a dynamically growing array.
You can add elements to it as follows:
ArrayList list = new ArrayList();
list.add(someObject);
list.add(anotherBoject);
The list will grow as new items are added to it. Therefore, you do not need to know the size in advance.
, toArray() .
Object[] arr = list.toArray(new Object[list.size()]);
Edit:
, :
List<Ser> objTest2 = new ArrayList<Ser>();
while (testOS2.available > 0) {
Ser toAdd = ((Ser)testOS2.readObject());
toAdd.printIt();
objTest2.add(toAdd);
}
* , available() .