Example usage for java.util Collections fill

List of usage examples for java.util Collections fill

Introduction

In this page you can find the example usage for java.util Collections fill.

Prototype

public static <T> void fill(List<? super T> list, T obj) 

Source Link

Document

Replaces all of the elements of the specified list with the specified element.

Usage

From source file:MainClass.java

public static void main(String[] a) {
    List list = new ArrayList(10);
    Object anObject = "A";
    list.add("N");
    Collections.fill(list, anObject);
    System.out.println(list);//from w w  w .  j a v  a  2 s.  c o m
    System.out.println(list.size());
}

From source file:MainClass.java

public static void main(String[] args) {
    List list = new ArrayList();
    for (int i = 0; i < 10; i++)
        list.add("");
    Collections.fill(list, "Hello");
    System.out.println(list);//from  w w  w . j a  va  2 s  .  c o m
}

From source file:Main.java

public static void main(String[] args) {
    List<String> list = new ArrayList<String>();
    for (int i = 0; i < 10; i++)
        list.add("");
    Collections.fill(list, "Hello");
    System.out.println(list);/*from w w w  . j  a va 2s  .c om*/
}

From source file:Main.java

public static void main(String[] args) {
    Vector<String> v = new Vector<String>();

    v.add("A");//  w  w  w.j a va  2  s  .c o  m
    v.add("B");
    v.add("D");

    System.out.println(v);
    Collections.fill(v, "REPLACED");
    System.out.println(v);
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> arrayList = new ArrayList<String>();
    arrayList.add("A");
    arrayList.add("B");
    arrayList.add("D");

    System.out.println(arrayList);
    Collections.fill(arrayList, "REPLACED");
    System.out.println(arrayList);

}

From source file:Main.java

public static void main(String[] args) {
    String[] coins = { "A", "B", "C", "D", "E" };

    List src = new LinkedList();
    for (int i = 0; i < coins.length; i++) {
        src.add(coins[i]);/*from w w w .  j  a  v  a 2  s. c  o m*/
    }

    System.out.println(src);

    Collections.fill(src, "java2s.com");

    Iterator liter = src.listIterator();

    while (liter.hasNext())
        System.out.println(liter.next());

}

From source file:Main.java

public static void main(String args[]) {
    // create array list object       
    List<String> arrlist = new ArrayList<String>();

    // populate the list
    arrlist.add("A");
    arrlist.add("B");
    arrlist.add("from java2s.com");

    System.out.println("List elements before fill: " + arrlist);

    // fill the list
    Collections.fill(arrlist, "java2s.com");

    System.out.println("List elements after fill: " + arrlist);
}

From source file:MainClass.java

public static void main(String[] args) {
    String[] coins = { "A", "B", "C", "D", "E" };

    List src = new LinkedList();
    for (int i = 0; i < coins.length; i++)
        src.add(coins[i]);/*from   w ww.  j av a 2 s .  c om*/

    List dst = new ArrayList();
    for (int i = 0; i < coins.length; i++)
        dst.add("");

    Collections.copy(dst, src);

    ListIterator liter = dst.listIterator();

    while (liter.hasNext())
        System.out.println(liter.next());

    Collections.fill(src, "no coins");

    liter = src.listIterator();

    while (liter.hasNext())
        System.out.println(liter.next());
}

From source file:Utilities.java

public static void main(String[] args) {
    List list = Arrays.asList("one Two three Four five six one".split(" "));
    System.out.println(list);/*w  w w.j a  v a2s.co  m*/
    System.out.println("max: " + Collections.max(list));
    System.out.println("min: " + Collections.min(list));
    AlphabeticComparator comp = new AlphabeticComparator();
    System.out.println("max w/ comparator: " + Collections.max(list, comp));
    System.out.println("min w/ comparator: " + Collections.min(list, comp));
    List sublist = Arrays.asList("Four five six".split(" "));
    System.out.println("indexOfSubList: " + Collections.indexOfSubList(list, sublist));
    System.out.println("lastIndexOfSubList: " + Collections.lastIndexOfSubList(list, sublist));
    Collections.replaceAll(list, "one", "Yo");
    System.out.println("replaceAll: " + list);
    Collections.reverse(list);
    System.out.println("reverse: " + list);
    Collections.rotate(list, 3);
    System.out.println("rotate: " + list);
    List source = Arrays.asList("in the matrix".split(" "));
    Collections.copy(list, source);
    System.out.println("copy: " + list);
    Collections.swap(list, 0, list.size() - 1);
    System.out.println("swap: " + list);
    Collections.fill(list, "pop");
    System.out.println("fill: " + list);
    List dups = Collections.nCopies(3, "snap");
    System.out.println("dups: " + dups);
    // Getting an old-style Enumeration:
    Enumeration e = Collections.enumeration(dups);
    Vector v = new Vector();
    while (e.hasMoreElements())
        v.addElement(e.nextElement());
    // Converting an old-style Vector
    // to a List via an Enumeration:
    ArrayList arrayList = Collections.list(v.elements());
    System.out.println("arrayList: " + arrayList);

}

From source file:Main.java

public static <T extends Object> void fill(final List<? super T> list, final T element) {
    Collections.fill(list, element);
}