Java List Transpose transpose(List> table)

Here you can find the source of transpose(List> table)

Description

transpose

License

Open Source License

Declaration

public static <T> List<List<T>> transpose(List<List<T>> table) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    public static <T> List<List<T>> transpose(List<List<T>> table) {
        List<List<T>> ret = new ArrayList<List<T>>();
        final int N = table.get(0).size();
        for (int i = 0; i < N; i++) {
            List<T> col = new ArrayList<T>();
            for (List<T> row : table) {
                col.add(row.get(i));//from w w  w. j a  v a2s .c  o  m
            }
            ret.add(col);
        }
        return ret;
    }
}

Related

  1. transpose(List> input)
  2. transpose(List> matrix)
  3. transpose(List> matrix)