CSVParser implements Iterable<CSVRecord>, Closeable { public Map<String, Integer> getHeaderMap() { return new LinkedHashMap<String, Integer>(this.headerMap); } CSVParser(final Reader reader, final CSVFormat format); static CSVParser parse(File file, final CSVFormat format); static CSVParser parse(String string, final CSVFormat format); static CSVParser parse(URL url, Charset charset, final CSVFormat format); void close(); long getCurrentLineNumber(); Map<String, Integer> getHeaderMap(); long getRecordNumber(); List<CSVRecord> getRecords(); boolean isClosed(); Iterator<CSVRecord> iterator();  }
@Test public void testGetHeaderMap() throws Exception { final CSVParser parser = CSVParser.parse("a,b,c\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader("A", "B", "C")); final Map<String, Integer> headerMap = parser.getHeaderMap(); final Iterator<String> columnNames = headerMap.keySet().iterator(); Assert.assertEquals("A", columnNames.next()); Assert.assertEquals("B", columnNames.next()); Assert.assertEquals("C", columnNames.next()); final Iterator<CSVRecord> records = parser.iterator(); for (int i = 0; i < 3; i++) { assertTrue(records.hasNext()); final CSVRecord record = records.next(); assertEquals(record.get(0), record.get("A")); assertEquals(record.get(1), record.get("B")); assertEquals(record.get(2), record.get("C")); } assertFalse(records.hasNext()); }