@@ -884,11 +884,21 @@ public String format(final Object... values) {
884884 }
885885 }
886886
887+ /**
888+ * Returns true if and only if duplicate names are allowed in the headers.
889+ *
890+ * @return whether duplicate header names are allowed
891+ * @since 1.7
892+ */
893+ public boolean getAllowDuplicateHeaderNames () {
894+ return duplicateHeaderMode == DuplicateHeaderMode .ALLOW_ALL ;
895+ }
896+
887897 /**
888898 * Returns how duplicate headers are handled.
889899 *
890900 * @return if duplicate header values are allowed, allowed conditionally, or disallowed.
891- * @since 1.7
901+ * @since 1.9
892902 */
893903 public DuplicateHeaderMode getDuplicateHeaderMode () {
894904 return duplicateHeaderMode ;
@@ -1686,13 +1696,30 @@ public CSVFormat withAllowDuplicateHeaderNames() {
16861696 return withDuplicateHeaderMode (DuplicateHeaderMode .ALLOW_ALL );
16871697 }
16881698
1699+ /**
1700+ * Returns a new {@code CSVFormat} with duplicate header names behavior set to the given value.
1701+ *
1702+ * @param allowDuplicateHeaderNames the duplicate header names behavior, true to allow, false to disallow.
1703+ * @return a new {@code CSVFormat} with duplicate header names behavior set to the given value.
1704+ * @since 1.7
1705+ */
1706+ public CSVFormat withAllowDuplicateHeaderNames (final boolean allowDuplicateHeaderNames ) {
1707+ final DuplicateHeaderMode mode =
1708+ (allowDuplicateHeaderNames ) ? DuplicateHeaderMode .ALLOW_ALL : DuplicateHeaderMode .ALLOW_EMPTY ;
1709+
1710+ return new CSVFormat (delimiter , quoteCharacter , quoteMode , commentMarker , escapeCharacter ,
1711+ ignoreSurroundingSpaces , ignoreEmptyLines , recordSeparator , nullString , headerComments , header ,
1712+ skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter , autoFlush ,
1713+ mode );
1714+ }
1715+
16891716 /**
16901717 * Returns a new {@code CSVFormat} with duplicate header names behavior set to the given value.
16911718 *
16921719 * @param duplicateHeaderMode the duplicate header names behavior, to allow, allow conditionally,
16931720 * or disable duplicates.
16941721 * @return a new {@code CSVFormat} with duplicate header names behavior set to the given value.
1695- * @since 1.7
1722+ * @since 1.9
16961723 */
16971724 public CSVFormat withDuplicateHeaderMode (final DuplicateHeaderMode duplicateHeaderMode ) {
16981725 return new CSVFormat (delimiter , quoteCharacter , quoteMode , commentMarker , escapeCharacter ,
0 commit comments