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