code: public static <T> void fill(List<? super T> list, T obj) {
          int size = list.size();
  
          if (size < FILL_THRESHOLD || list instanceof RandomAccess) {
              for (int i=0; i<size; i++)
                  list.set(i, obj);
          } else {
              ListIterator<? super T> itr = list.listIterator();
              for (int i=0; i<size; i++) {
                  itr.next();
                  itr.set(obj);
              }
          }
      }
docs: Replaces all of the elements of the specified list with the specified
  element. <p>
  
  This method runs in linear time.
  
  @param  <T> the class of the objects in the list
  @param  list the list to be filled with the specified element.
  @param  obj The element with which to fill the specified list.
  @throws UnsupportedOperationException if the specified list or its
  list-iterator does not support the <tt>set</tt> operation.