code: public static <T> List<T> readList(ObjectDataInput in) throws IOException {
          int size = in.readInt();
          if (size == 0) {
              return Collections.emptyList();
          }
          List<T> list = new ArrayList<>(size);
          for (int i = 0; i < size; i++) {
              T item = in.readObject();
              list.add(item);
          }
          return list;
      }
docs: Reads a list from the given {@link ObjectDataInput}. It is expected that
  the next int read from the data input is the list's size, then that
  many objects are read from the data input and returned as a list.
  
  @param in    data input to read from
  @param <T>   type of items
  @return      list of items read from data input
  @throws IOException  when an error occurs while reading from the input