How to transpose List?

前端 未结 10 759
温柔的废话
温柔的废话 2021-01-01 17:59

I have a following ArrayList,

[Title,Data1,Data2,Data3]
[A,2,3,4]
[B,3,5,7]

And I would like to convert this one like this,



        
10条回答
  •  南笙
    南笙 (楼主)
    2021-01-01 18:39

    The mathematics behind: you need to transpose the matrix. It's easier if you use a 2-dimensional array or a 'List of Lists', which is pretty much he same with collections. A List of arrays works too, but it is slightly more confusing.

    This wikipedia article shows some algorithms for transposition.

提交回复
热议问题