Example usage for java.util List set

List of usage examples for java.util List set

Introduction

In this page you can find the example usage for java.util List set.

Prototype

E set(int index, E element);

Source Link

Document

Replaces the element at the specified position in this list with the specified element (optional operation).

Usage

From source file:Main.java

public static Integer incrementAndGet(List<Integer> list, int index) {
    Integer integer = list.get(index);
    return list.set(index, integer + 1);
}

From source file:Main.java

public static void set(List list, int index, Object value) {
    while (index >= list.size())
        list.add(null);/*from w  ww. j a v  a  2s. c  o  m*/
    list.set(index, value);
}

From source file:Main.java

public static <E> void swap(final List<E> list, final int i, final int j) {
    if (list instanceof RandomAccess) {
        list.set(i, list.set(j, list.get(i)));
    } else {/*from w w w .  ja  v  a2 s  . com*/
        final ListIterator<E> iterator = list.listIterator(i);
        iterator.set(list.set(j, iterator.next()));
    }
}

From source file:Main.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void listSet(List obj, int index, Object value) {
    int length = obj.size();
    if (index < 0)
        index += length;/*from   w w w. j av  a  2 s.c  om*/
    obj.set(index, value);
}

From source file:beyondlambdas.slides.s8_1.Support.java

public static Stream<String> badJsonData() {
    final List<Integer> integers = IntStream.rangeClosed(1, 20).boxed().collect(toList());
    integers.set(12, 21);
    return integers.stream().map(Support::item);
}

From source file:Main.java

public static <T> void fill(List<T> list, int start, int end, Class<T> clazz) {
    for (int i = start; i <= end; i++) {
        try {//w  w w.  j av a  2s.c o  m

            list.set(i, clazz != null ? clazz.newInstance() : null);

        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:Main.java

/**
 * Swap item in <code>list</code> at position <code>firstIndex</code> with item at position <code>secondIndex</code>
 *
 * @param list The list in which to swap the items.
 * @param firstIndex The position of the first item in the list.
 * @param secondIndex The position of the second item in the list.
 */// w  ww  .  j  a v a 2  s  .  c om
public static void swap(List list, int firstIndex, int secondIndex) {
    Object firstObject = list.get(firstIndex);
    Object secondObject = list.get(secondIndex);
    list.set(firstIndex, secondObject);
    list.set(secondIndex, firstObject);
}

From source file:Main.java

public static <E> E removeReplace(List<E> list, int index) {
    int lastIdx = list.size() - 1;
    E last = list.remove(lastIdx);//from w w w. j a  va  2  s.  c o m
    if (lastIdx != index) {
        list.set(index, last);
        return last;
    }
    return null;
}

From source file:Main.java

public static <E> void swap(List<E> list, int i, int j) {
    E tmp = list.get(i);//from w w  w .j av a 2 s.com
    list.set(i, list.get(j));
    list.set(j, tmp);
}

From source file:ml.shifu.shifu.util.QuickSort.java

private static <T> void exchange(List<T> values, int i, int j) {
    T tmp = values.get(i);//from w w w  . j av a2 s .  co  m
    values.set(i, values.get(j));
    values.set(j, tmp);
}