Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Split a List into a Map (https://www.askmehelpdesk.com/showthread.php?t=769097)

  • Sep 28, 2013, 02:12 AM
    youknowwhoo
    Split a List into a Map
    I need to achieve the following scenario.

    1) Create a Employee Class with empID, department and empName.
    2) Create a List for the employees with different values.
    3) Split the employee list into a map such that the department is the key and value is the list of employees.

    I am stuck with the 3rd point.
    Please find my code below:

    Class Student
    package com.student;

    public class Student {
    private int studentID;
    private String branchName;
    private String studentName;
    private int age;

    public Student()
    {
    this.studentID = 1;
    this.studentName = "default";
    this.branchName = "default";
    this.age = 1;
    }

    public Student(int id,String branch,String stname,int age)
    {
    this.studentID = id;
    this.branchName = branch;
    this.studentName = stname;
    this.age = age;
    }

    }


    Class StudentList
    package com.student;

    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;

    public class StudentList {

    /**
    * @param args
    */
    static List<Student> stList = new ArrayList<Student>();

    public static void populateStudentList(Student student)
    {
    stList.add(student);
    }

    public static void splitList()
    {

    }
    public static void main(String[] args) {
    Student student1 = new Student(1, "IT", "Antara", 23);
    Student student2 = new Student(2, "IT", "Madhuja", 23);
    Student student3 = new Student(3, "IT", "Sukanya", 23);
    Student student4 = new Student(4, "CSE", "Arnab", 23);
    Student student5 = new Student(5, "CSE", "Papia", 23);

    populateStudentList(student1);
    populateStudentList(student2);
    populateStudentList(student3);
    populateStudentList(student4);
    populateStudentList(student5);

    splitList();
    //System.out.println("The Student List Contains:: "+ stList);

    }

    }

  • All times are GMT -7. The time now is 09:13 PM.