code: static void checkArrayForDuplicates(Object[] array, String arrayName) {
          if (array.length > 1) {
              if (array.length == 2) {
                  if (array[0] == array[1] || 
                          (array[0] != null && array[0].equals(array[1]))) {
                      throw new IllegalArgumentException(arrayName
                              + " cannot contain duplicate elements: "
                              + Arrays.toString(array) + "; " + array[0]);
                  }
              } else {
                  Set<Object> set = new HashSet<>();
                  for (Object obj : array) {
                      if (!set.add(obj)) {
                          throw new IllegalArgumentException(arrayName
                                  + " cannot contain duplicate elements: "
                                  + Arrays.toString(array) + "; " + obj);
                      }
                  }
              }
          }
      }
docs: Checks an array for duplicates as checked with the <code>equals</code>
  method.
  
  @param array an {@link Object[]}. Cannot be <code>null</code>.
  @param arrayName the name {@link String} of the array to use in the
  error message if a duplicate is found.
  @throws IllegalArgumentException if a duplicate is found.