File tree Expand file tree Collapse file tree
src/main/java/org/apache/commons/csv Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3333import java .nio .file .Path ;
3434import java .util .ArrayList ;
3535import java .util .Arrays ;
36+ import java .util .Collections ;
3637import java .util .Iterator ;
3738import java .util .List ;
3839import java .util .Map ;
@@ -183,9 +184,13 @@ public void remove() {
183184 }
184185
185186 static List <String > createHeaderNames (final Map <String , Integer > headerMap ) {
187+ // @formatter:off
186188 return headerMap == null ? null
187- : headerMap .entrySet ().stream ().sorted (Map .Entry .comparingByValue ()).map (Map .Entry ::getKey )
188- .collect (Collectors .toList ());
189+ : headerMap .entrySet ().stream ()
190+ .sorted (Map .Entry .comparingByValue ())
191+ .map (Map .Entry ::getKey )
192+ .collect (Collectors .collectingAndThen (Collectors .toList (), Collections ::unmodifiableList ));
193+ // @formatter:on
189194 }
190195
191196 /**
@@ -543,13 +548,13 @@ Map<String, Integer> getHeaderMapRaw() {
543548 }
544549
545550 /**
546- * Returns a copy of the header names that iterates in column order.
551+ * Returns a read-only list of header names that iterates in column order.
547552 *
548- * @return a copy of the header names that iterates in column order.
553+ * @return read-only list of header names that iterates in column order.
549554 * @since 1.7
550555 */
551556 public List <String > getHeaderNames () {
552- return new ArrayList <>( headerNames ) ;
557+ return headerNames ;
553558 }
554559
555560 /**
You can’t perform that action at this time.
0 commit comments