How to transpose the list in java

2015-10-20T01:33:37

I want to transpose my list

Assume I am having the studentList

List<Student> studentList = new ArrayList<Student>();
studentList.add(new Student(101, "English", "95"));
studentList.add(new Student(101, "Maths", "82"));
studentList.add(new Student(101, "Biology", "93"));
studentList.add(new Student(101, "Physics", "77"));
studentList.add(new Student(101, "Chemistry", "65"));
studentList.add(new Student(102, "English", "86"));
studentList.add(new Student(102, "Maths", "75"));
studentList.add(new Student(102, "Biology", "68"));
studentList.add(new Student(102, "Physics", "63"));
studentList.add(new Student(102, "Chemistry", "84"));
studentList.add(new Student(103, "English", "92"));
studentList.add(new Student(103, "Maths", "88"));
studentList.add(new Student(103, "Biology", "67"));
studentList.add(new Student(103, "Physics", "81"));
studentList.add(new Student(103, "Chemistry", "93"));

public class Student {

    private Integer rollNo;

    private String subject;

    private String marks;

..........
}

I want to transpose this data to the StudentResultList

List<StudentResult> studentResultList = new ArrayList<StudentResult>();


public class StudentResult {

    private String rollno;

    private String english;

    private String maths;

    private String biology;

    private String physics;

    private String chemistry;

..........

}

Expected Output:

            101         102         103

English     95          86          92

Maths       82          75          88

Biology     93          68          67  

Physics     77          63          81  

Chemistry   65          84          93  

What collection i have to use to transpose my list?

I tried to convert using

HashMap<Integer,Object> (Integer is RollNo,Object is another hashmap)

HashMap<String, String> (String is Subject and the another String is marks)

Using this i am converting the studentlist to studentResultlist.

Anybody suggest me, Is there any better way to transpose the list?

Copyright License:
Author:「Martin」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/33220520/how-to-transpose-the-list-in-java

About “How to transpose the list in java” questions

I want to transpose my list Assume I am having the studentList List&lt;Student&gt; studentList = new ArrayList&lt;Student&gt;(); studentList.add(new Student(101, "English", "95")); studentList
1.I use cv2.imread to read a big image in numpy array (1234*1624*3) 2.I use cv2.dnn.blobFromImage to transform it to (1,3,1234,1624) numpy array 3.I use tolist() to transform it to a 4D list in l...
I would like to transpose a nested list. Assume the following nested list x is given: a &lt;- list(c("a","b","c","d")) b &lt;- list(c("d","c","b","a"))&#x
I hope that this will be quite easy for some of you. I found this solution in this forum: let rec transpose list = match list with | [] -&gt; [] | [] :: xss -&gt; transpose xss | ...
I'm trying to make a recursive function to get the transpose of a list of lists, n x p to p x n. But i'm unable to do so. I've been able to make a function to transpose a 3 x n list of lists to an ...
I got a list of lists in racket and have to transpose them. (: transpose ((list-of(list-of %a)) -&gt; (list-of (list-of %a)))) (check-expect (transpose (list (list 1 2 3) ...
I got a list of lists in racket and have to transpose them. (: transpose ((list-of(list-of %a)) -&gt; (list-of (list-of %a)))) (check-expect (transpose (list (list 1 2 3) ...
Well, i've been told to make a Matrix Transpose function in common lisp. I'm a beginner, so i don't know so much of it. My Matrix is a list of lists, and i can't use apply, mapcar or similar to so...
Suppose i have a nested list m = [[2, 3], [4, 7]] and I want to transpose it such that I get [[2, 4], [3, 7]] OR if m can be [[1,2,3],[4,5,6],[7,8,9]] then after passing through the transpose fun...
how can I write a program in java to find the transpose of the graph G, where the input and the output of the program are represented as adjacency list structure. for example: input: 1>2>3>4...

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.