Java Utililty Methods List Swap

List of utility methods to do List Swap

Description

The list of methods to do List Swap are organized into topic(s).

Method

Listswap(List list, int minIndex, int maxIndex)
Method to swap elements at two indexes
if (list != null && list.size() > 2 && maxIndex > minIndex) {
    List<T> updatedList = new ArrayList<>();
    T elementAtMinIndex = list.get(minIndex);
    T elementAtMaxIndex = list.get(maxIndex);
    for (int i = 0; i < list.size(); i++) {
        if (i != minIndex && i != maxIndex) {
            updatedList.add(i, list.get(i));
        } else if (i == minIndex) {
...
voidswapElements(List list, T element1, T element2)
swap Elements
int index1 = list.indexOf(element1);
int index2 = list.indexOf(element2);
if (index1 == -1 || index1 == -1) {
    return;
Collections.swap(list, index1, index2);
voidswapItems(final List data, int from, int to)
Swaps 2 items
if (from == to)
    return;
if (!hasElements(data))
    return;
if (from < 0 || from >= data.size()) {
    throw new IllegalArgumentException("'from' must be within 0 to n-1");
if (to < 0 || to >= data.size()) {
...
voidswapListElements(List list, int idx1, int idx2)
swap List Elements
Object tmp = list.get(idx1);
list.set(idx1, list.get(idx2));
list.set(idx2, tmp);