本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}