Dave Thomas, the author of the Don’t Repeat Yourself principle said:

DRY says that every piece of system knowledge should have one

authoritative, unambiguous representation. Every piece of knowledge in

the development of something should have a single representation. A

system’s knowledge is far broader than just its code. It refers to

database schemas, test plans, the build system, even documentation.

I have difficulty to understand how it applies to programming code documentation.

Java API has the java.util.Arrays class with the *copyOf* method that is overloaded 7 times. The 8 methods can be documented in two ways containing the same information. The first way describes all overloaded methods using a single description, highlighting the differences between overloads. The second way describes each overloaded method using a separate description. Below are both ways – I bolded the differences in the content. The second way was literally copied from the API documentation of the java.util.Arrays class. Is the second way compliant with the DRY principle? In my opinion it isn’t, because it contains text which was copied multiple times, then, additionally, minor modifications were made to each copy. The same information can be provided in one text, which is almost eight times shorter.

```
public static byte() copyOf(byte() original, int newLength)
public static short() copyOf(short() original, int newLength)
public static int() copyOf(int() original, int newLength)
public static long() copyOf(long() original, int newLength)
public static float() copyOf(float() original, int newLength)
public static double() copyOf(double() original, int newLength)
public static char() copyOf(char() original, int newLength)
public static boolean() copyOf(boolean() original, int newLength)
```

Copies the specified array, truncating or padding with **the default values** (if necessary) so the copy has the specified length. For all indices that are valid in both the original array and the copy, the two arrays will contain identical values. For any indices that are valid in the copy but not the original, the copy will contain **the default value**. Such indices will exist if and only if the specified length is greater than that of the original array.

**The following table lists default values for given type of array elements:**

type |
the default value of type |

**byte, short, int, long** |
**0** |

**float, double** |
**0.0** |

**char** |
**null character (‘u0000’)** |

**boolean** |
**false** |

Parameters:

- original – the array to be copied
- newLength – the length of the copy to be returned

Returns: a copy of the original array, truncated or padded with **the default values** to obtain the specified length

Throws:

- NegativeArraySizeException – if newLength is negative
- NullPointerException – if original is null

Since: 1.6

```
public static byte() copyOf(byte() original, int newLength)
```

Copies the specified array, truncating or padding with **zeros** (if necessary) so the copy has the specified length. For all indices that are valid in both the original array and the copy, the two arrays will contain identical values. For any indices that are valid in the copy but not the original, the copy will contain **(byte)0**. Such indices will exist if and only if the specified length is greater than that of the original array.

Parameters:

- original – the array to be copied
- newLength – the length of the copy to be returned

Returns: a copy of the original array, truncated or padded with **zeros** to obtain the specified length

Throws:

- NegativeArraySizeException – if newLength is negative
- NullPointerException – if original is null

Since: 1.6

```
public static short() copyOf(short() original, int newLength)
```

Copies the specified array, truncating or padding with **zeros** (if necessary) so the copy has the specified length. For all indices that are valid in both the original array and the copy, the two arrays will contain identical values. For any indices that are valid in the copy but not the original, the copy will contain **(short)0**. Such indices will exist if and only if the specified length is greater than that of the original array.

Parameters:

- original – the array to be copied
- newLength – the length of the copy to be returned

Returns: a copy of the original array, truncated or padded with **zeros** to obtain the specified length

Throws:

- NegativeArraySizeException – if newLength is negative
- NullPointerException – if original is null

Since: 1.6

```
public static int() copyOf(int() original, int newLength)
```

Copies the specified array, truncating or padding with **zeros** (if necessary) so the copy has the specified length. For all indices that are valid in both the original array and the copy, the two arrays will contain identical values. For any indices that are valid in the copy but not the original, the copy will contain **0**. Such indices will exist if and only if the specified length is greater than that of the original array.

Parameters:

- original – the array to be copied
- newLength – the length of the copy to be returned

Returns: a copy of the original array, truncated or padded with **zeros** to obtain the specified length

Throws:

- NegativeArraySizeException – if newLength is negative
- NullPointerException – if original is null

Since: 1.6

```
public static long() copyOf(long() original, int newLength)
```

Copies the specified array, truncating or padding with **zeros** (if necessary) so the copy has the specified length. For all indices that are valid in both the original array and the copy, the two arrays will contain identical values. For any indices that are valid in the copy but not the original, the copy will contain **0L**. Such indices will exist if and only if the specified length is greater than that of the original array.

Parameters:

- original – the array to be copied
- newLength – the length of the copy to be returned

Returns: a copy of the original array, truncated or padded with **zeros** to obtain the specified length

Throws:

- NegativeArraySizeException – if newLength is negative
- NullPointerException – if original is null

Since: 1.6

```
public static char() copyOf(char() original, int newLength)
```

Copies the specified array, truncating or padding with **null characters** (if necessary) so the copy has the specified length. For all indices that are valid in both the original array and the copy, the two arrays will contain identical values. For any indices that are valid in the copy but not the original, the copy will contain **‘u0000’**. Such indices will exist if and only if the specified length is greater than that of the original array.

Parameters:

- original – the array to be copied
- newLength – the length of the copy to be returned

Returns: a copy of the original array, truncated or padded with **null characters** to obtain the specified length

Throws:

- NegativeArraySizeException – if newLength is negative
- NullPointerException – if original is null

Since: 1.6

```
public static float() copyOf(float() original, int newLength)
```

Copies the specified array, truncating or padding with **zeros** (if necessary) so the copy has the specified length. For all indices that are valid in both the original array and the copy, the two arrays will contain identical values. For any indices that are valid in the copy but not the original, the copy will contain **0f**. Such indices will exist if and only if the specified length is greater than that of the original array.

Parameters:

- original – the array to be copied
- newLength – the length of the copy to be returned

Returns: a copy of the original array, truncated or padded with **zeros** to obtain the specified length

Throws:

- NegativeArraySizeException – if newLength is negative
- NullPointerException – if original is null

Since: 1.6

```
public static double() copyOf(double() original, int newLength)
```

Copies the specified array, truncating or padding with **zeros** (if necessary) so the copy has the specified length. For all indices that are valid in both the original array and the copy, the two arrays will contain identical values. For any indices that are valid in the copy but not the original, the copy will contain **0d**. Such indices will exist if and only if the specified length is greater than that of the original array.

Parameters:

- original – the array to be copied
- newLength – the length of the copy to be returned

Returns: a copy of the original array, truncated or padded with **zeros** to obtain the specified length

Throws:

- NegativeArraySizeException – if newLength is negative
- NullPointerException – if original is null

Since: 1.6

```
public static boolean() copyOf(boolean() original, int newLength)
```

Copies the specified array, truncating or padding with **false** (if necessary) so the copy has the specified length. For all indices that are valid in both the original array and the copy, the two arrays will contain identical values. For any indices that are valid in the copy but not the original, the copy will contain **false**. Such indices will exist if and only if the specified length is greater than that of the original array.

Parameters:

- original – the array to be copied
- newLength – the length of the copy to be returned

Returns: a copy of the original array, truncated or padded with **false elements** to obtain the specified length

Throws:

- NegativeArraySizeException – if newLength is negative
- NullPointerException – if original is null

Since: 1.6