// note: instantiating with a.size() gives `b` enough capacity to hold everything List<String> b = new ArrayList<String>(a.size()); Collections.copy(b, a);
static List<List<Integer>> getAllConstraintCombinations() { List<List<Integer>> combos = new ArrayList<>(); combos.add(Collections.<Integer>emptyList()); for (Integer cur : Constraint.ALL_CONSTRAINTS) { for (int l = combos.size() - 1; l >= 0; l--) { List<Integer> oldCombo = combos.get(l); List<Integer> newCombo = Arrays.asList(new Integer[oldCombo.size() + 1]); Collections.copy(newCombo, oldCombo); newCombo.set(oldCombo.size(), cur); combos.add(newCombo); } combos.add(Collections.singletonList(cur)); } return combos; }
//assume oldList exists and has data in it. List<String> newList = new ArrayList<String>(); Collections.copy(newList, oldList);
ArrayList copy = new ArrayList (original.size()); Collections.copy(copy, original);
for(ArrayList<Arc> list : rotalar1) { ArrayList<Arc> copy = new ArrayList<>(); Collections.copy(copy, list); //or copy.addAll(list); rotalar2.add(copy); }
List<Flight> a = new ArrayList<>(); List<Flight> copy = new ArrayList<>(); Collections.copy(copy, a); Iterator<Flight> it = a.iterator(); while(it.hasNext()){ Flight f = it.next(); if(shouldGetRemoved(f, copy)){ it.remove(); } }
private <U extends BaseAuditModule> List<U> copyAndAdd(final List<U> orig, final U am) { final List<U> list = new ArrayList<U>(); Collections.copy(orig, list); list.add(am); return list; }
public static <T extends Object> List<T> reverse(List<T> list) { List<T> copy = Collections.emptyList(); Collections.copy(copy, list); Collections.reverse(copy); return copy; }
private <U extends BaseAuditModule> List<U> copyAndRemove(final List<U> orig, final U am) { final List<U> list = new ArrayList<U>(); Collections.copy(orig, list); list.remove(am); return list; }
List<String> originalList = Arrays.asList(ARRAY_ARGS); List<String> list = new ArrayList<String>(originalList); Collections.copy(list, originalList); list.add(additionalArgument); foo(list.toArray(new String[list.size()]));
public ControlEffectAttributes( @Nonnull final Attributes attributes, @Nonnull final List<EffectValueType> effectValues) { this.attributes = new Attributes(attributes); this.effectValues = new ArrayList<EffectValueType>(effectValues); Collections.copy(this.effectValues, effectValues); }
public static List<Field> getAllFields(Class<?> objClass) { AssertUtils.notNull(objClass); List<Field> fields = new ArrayList<Field>(0); while (!objClass.getSuperclass().equals(Object.class)) { Collections.copy(fields, Arrays.asList(objClass.getDeclaredFields())); objClass = objClass.getSuperclass(); } return fields; }
private Stack<MethodCall> copyCallStack(Stack<MethodCall> callStack) { Stack<MethodCall> r = new Stack<MethodCall>(); r.setSize(callStack.size()); Collections.copy(r, callStack); return r; }
public List<RestaurantData> sort(RArrayList<RestaurantData> datas) { // Create a list with enough capacity for all elements List<RestaurantData> newList = new RArrayList<RestaurantData>(datas.size()); Collections.copy(newList, datas); Collections.sort(newList, new Comparator<RestaurantData>() { @Override public int compare(RestaurantData lhs, RestaurantData rhs) { return lhs.getDistance() - rhs.getDistance(); } }); return newList; }
public ControlEffectOnHoverAttributes( @Nonnull final Attributes attributes, @Nonnull final List<EffectValueType> effectValues, @Nonnull final HoverType hoverType) { this.attributes = new Attributes(attributes); this.effectValues = new ArrayList<EffectValueType>(effectValues); Collections.copy(this.effectValues, effectValues); this.controlHoverAttributes = new ControlHoverAttributes(hoverType); }
List<? extends Fruit> basket = new ArrayList<? extends Fruit>(); basket.add(new Apple()); basket.add(new Pear()); basket.add(new Tomato()); List<Fruit> fridge = new ArrayList<Fruit>(); Collections.copy(fridge, basket);// works
List<Apple> basket = new ArrayList<Apple>(); basket.add(new Apple()); basket.add(new Apple()); basket.add(new Apple()); List<Fruit> fridge = new ArrayList<Fruit>(); Collections.copy(fridge, basket); /* works since the basket is defined as a List of apples and not a list of some fruits. */
default MaterializedListChange<E> materialize() { List<E> added = new ArrayList<>(getAddedSize()); Collections.copy(added, getAddedSublist()); added = Collections.unmodifiableList(added); return new MaterializedListChangeImpl<>(getFrom(), getRemoved(), added); }
private void countItems(EntityPlayer player, ItemStack stack) { if(!player.getEntityWorld().isRemote){ NonNullList<ItemStack> items = NonNullList.withSize(player.inventory.mainInventory.size() + 1, ItemStack.EMPTY); Collections.copy(items, player.inventory.mainInventory); if(!stack.isEmpty()){ items.set(items.size() - 1, stack); } countItems(items, (QuestDataTaskItems) getData(player), player.getPersistentID()); } }