Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rollno user_name user_email_id class_type request_status
- --------------------------------------------------------------
- CM5C9CBJJP Isaac James isaac.james@gmail.com 1 Accepted
- E6U13NFHGG Sean Allan sean.allan@gmail.com 1 Deactivated
- SNAJHHVV8Q Dylan Avery dylan.avery@gmail.com 1 Accepted
- RNN71FJ5QS Max Fisher max.fisher@gmail.com 1 Rejected
- 6NKKI603BM Owen Grant owen.grant@gmail.com 1 Deactivated
- public class StoreStudents {
- public static void main(String[] args) throws IOException {
- //HashMap Declaration.
- HashMap<String, List<String>> map = new HashMap<>();
- List<String> studentData = new ArrayList<>();
- // Read Excel FIle Sheet
- File excelFile = new File("user_details.xlsx");
- FileInputStream fis = new FileInputStream(excelFile);
- XSSFWorkbook workbook = new XSSFWorkbook(fis);
- XSSFSheet sheet = workbook.getSheetAt(0);
- Iterator<Row> rowIt = sheet.iterator();
- String k1 = "default";
- int count = 0,objCount = 0;
- while(rowIt.hasNext()) {
- count = count + 1;
- Row row = rowIt.next();
- // iterate on cells for the current row
- Iterator<Cell> cellIterator = row.cellIterator();
- if (row.getRowNum() != 0) {
- while (cellIterator.hasNext()) {
- Cell cell = cellIterator.next();
- //System.out.println(cell.getColumnIndex());
- if (cell.getColumnIndex() == 0) {
- k1 = cell.toString();
- System.out.println("1. key is " + k1);
- }
- else {
- studentData.add(cell.toString());
- //System.out.println(studentData);
- //System.out.print(cell.toString() + ";");
- }
- }
- }
- System.out.println("key is " + k1);
- map.put(k1, studentData);
- System.out.println(map);
- studentData.clear();
- System.out.println(map);
- objCount = objCount + 1;
- }
- }
- }
- Output:
- key is default
- {default=[]}
- 1. key is CM5C9CBJJP
- key is CM5C9CBJJP
- {CM5C9CBJJP=[Isaac James, isaac.james@gmail.com, 1.0, Accepted], default=[Isaac James, isaac.james@gmail.com, 1.0, Accepted]}
- 1. key is E6U13NFHGG
- key is E6U13NFHGG
- {CM5C9CBJJP=[Sean Allan, sean.allan@gmail.com, 1.0, Deactivated], default=[Sean Allan, sean.allan@gmail.com, 1.0, Deactivated], E6U13NFHGG=[Sean Allan, sean.allan@gmail.com, 1.0, Deactivated]}
- 1. key is SNAJHHVV8Q
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement