How to transpose List?

前端 未结 10 682
温柔的废话
温柔的废话 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 19:01

    Do you have a fixed number of ArrayLists and are they of fixed size to begin with? If it is fixed, what you can do is have an int index value and process each ArrayList in turn in the same loop. You can then transfer each value to a temporary ArrayList and then place a reference to this in a final ArrayList for output.

    Sounds confusing? Here's a rough solution:

    ArrayList tempList = new ArrayList();
    ArrayList outputList = new ArrayList();
    
    for(index=0;index

提交回复
热议问题