Java Utililty Methods List Rotate

List of utility methods to do List Rotate

Description

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

Method

voidrotate(final List list, int n)
Rotate a list by N places.
final int len = list.size();
if (len <= 0 || n == 0)
    return;
n %= len;
if (n > 0) {
    for (; n > 0; n--) {
        T t = list.remove(0);
        list.add(t);
...
voidrotate(List a)
rotate
if (a.size() > 0) {
    Object tmp = a.remove(0);
    a.add(tmp);
Listrotate(List data, int n)
rotate
List<T> result = new ArrayList<>();
int len = n % data.size() + ((n < 0) ? data.size() : 0);
for (int i = 0; i < len; i++)
    result.add(data.get(data.size() + i - len));
for (int i = len; i < data.size(); i++)
    result.add(data.get(i - len));
return result;
List>rotateRowsOfMatrix(List> matrix)
rotate Rows Of Matrix
List<List<Integer>> result = new ArrayList<List<Integer>>();
for (int i = 0; i < matrix.size(); i++) {
    List<Integer> row = matrix.get(i);
    List<Integer> newRow = new ArrayList<Integer>();
    Integer temp0 = row.get(0);
    Integer temp1 = row.get(1);
    Integer temp2 = row.get(2);
    Integer temp3 = row.get(3);
...