当前位置: 首页>>代码示例>>Java>>正文


Java Collections.fill方法代码示例

本文整理汇总了Java中java.util.Collections.fill方法的典型用法代码示例。如果您正苦于以下问题:Java Collections.fill方法的具体用法?Java Collections.fill怎么用?Java Collections.fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Collections的用法示例。


在下文中一共展示了Collections.fill方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.util.Collections; //导入方法依赖的package包/类
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);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:21,代码来源:ReplaceAllElementsOfArrayListExample.java

示例2: main

import java.util.Collections; //导入方法依赖的package包/类
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);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:21,代码来源:ReplaceAllElementsOfVectorExample.java

示例3: replaceStackMoves

import java.util.Collections; //导入方法依赖的package包/类
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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:StackMoveOptimizationPhase.java

示例4: getPreloadItems

import java.util.Collections; //导入方法依赖的package包/类
@NonNull
@Override
public List<Object> getPreloadItems(int position) {
  ArrayList<Object> result = new ArrayList<>(1);
  Collections.fill(result, new Object());
  return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:ListPreloaderTest.java

示例5: main

import java.util.Collections; //导入方法依赖的package包/类
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);
}
 
开发者ID:cleitonferreira,项目名称:LivroJavaComoProgramar10Edicao,代码行数:28,代码来源:Algorithms1.java

示例6: changeArgTypes

import java.util.Collections; //导入方法依赖的package包/类
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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:MethodHandlesTest.java

示例7: getPreloadItems

import java.util.Collections; //导入方法依赖的package包/类
@Override
public List<Object> getPreloadItems(int position) {
  ArrayList<Object> result = new ArrayList<>(1);
  Collections.fill(result, new Object());
  return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:7,代码来源:ListPreloaderTest.java


注:本文中的java.util.Collections.fill方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。