Java Code Examples for java.util.Collections.fill()

The following are Jave code examples for showing how to use fill() of the java.util.Collections class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: javaide   File: ReplaceAllElementsOfArrayListExample.java   View Source Code Vote up 6 votes
public static void main(String[] args) {
  //create a ArrayList object
  ArrayList arrayList = new ArrayList();

  //Add elements to ArrayList
  arrayList.add("A");
  arrayList.add("B");
  arrayList.add("D");

  /*
    To replace all elements of Java ArrayList with specified element use,
    static void fill(List list, Object element) method of Collections class.
  */

  System.out.println("Before replacement, ArrayList contains : " + arrayList);

  Collections.fill(arrayList, "REPLACED");

  System.out.println("After replacement, ArrayList contains : " + arrayList);
}
 
Example 2
Project: javaide   File: ReplaceAllElementsOfVectorExample.java   View Source Code Vote up 6 votes
public static void main(String[] args) {
  //create a Vector object
  Vector v = new Vector();

  //Add elements to Vector
  v.add("A");
  v.add("B");
  v.add("D");

  /*
    To replace all elements of Java Vector with specified element use,
    static void fill(List list, Object element) method of Collections class.
  */

  System.out.println("Before replacement, Vector contains : " + v);

  Collections.fill(v, "REPLACED");

  System.out.println("After replacement, Vector contains : " + v);
}
 
Example 3
Project: openjdk-jdk10   File: StackMoveOptimizationPhase.java   View Source Code Vote up 6 votes
private void replaceStackMoves(DebugContext debug, List<LIRInstruction> instructions) {
    int size = dst.size();
    if (size > 1) {
        AMD64MultiStackMove multiMove = new AMD64MultiStackMove(dst.toArray(new AllocatableValue[size]), src.toArray(new AllocatableValue[size]), reg, slot);
        // replace first instruction
        instructions.set(begin, multiMove);
        // and null out others
        Collections.fill(instructions.subList(begin + 1, begin + size), null);
        // removed
        removed = true;
        eliminatedBackup.add(debug, size - 1);
    }
    // reset
    dst.clear();
    src.clear();
    begin = NONE;
    reg = null;
    slot = null;
}
 
Example 4
Project: GitHub   File: ListPreloaderTest.java   View Source Code Vote up 5 votes
@NonNull
@Override
public List<Object> getPreloadItems(int position) {
  ArrayList<Object> result = new ArrayList<>(1);
  Collections.fill(result, new Object());
  return result;
}
 
Example 5
Project: LivroJavaComoProgramar10Edicao   File: Algorithms1.java   View Source Code Vote up 5 votes
public static void main(String[] args)
{
   // create and display a List< Character >
   Character[] letters = {'P', 'C', 'M'};
   List<Character> list = Arrays.asList(letters); // get List
   System.out.println("list contains: ");
   output(list);

   // reverse and display the List<Character>
   Collections.reverse(list); // reverse order the elements
   System.out.printf("%nAfter calling reverse, list contains:%n");
   output(list);

   // create copyList from an array of 3 Characters
   Character[] lettersCopy = new Character[3]; 
   List<Character> copyList = Arrays.asList(lettersCopy); 

   // copy the contents of list into copyList
   Collections.copy(copyList, list);
   System.out.printf("%nAfter copying, copyList contains:%n");
   output(copyList);

   // fill list with Rs 
   Collections.fill(list, 'R'); 
   System.out.printf("%nAfter calling fill, list contains:%n");
   output(list);
}
 
Example 6
Project: openjdk-jdk10   File: MethodHandlesTest.java   View Source Code Vote up 5 votes
static MethodHandle changeArgTypes(MethodHandle target,
        int beg, int end, Class<?> argType) {
    MethodType targetType = target.type();
    end = Math.min(end, targetType.parameterCount());
    ArrayList<Class<?>> argTypes = new ArrayList<>(targetType.parameterList());
    Collections.fill(argTypes.subList(beg, end), argType);
    MethodType ttype2 = MethodType.methodType(targetType.returnType(), argTypes);
    return target.asType(ttype2);
}
 
Example 7
Project: GitHub   File: ListPreloaderTest.java   View Source Code Vote up 4 votes
@Override
public List<Object> getPreloadItems(int position) {
  ArrayList<Object> result = new ArrayList<>(1);
  Collections.fill(result, new Object());
  return result;
}