code: public static Optional<Object> getSubjectAltNameField(X509Certificate certificate, int field) {
          try {
              Collection<List<?>> subjectAltNames = certificate.getSubjectAlternativeNames();
              if (subjectAltNames == null) subjectAltNames = Collections.emptyList();
  
              for (List<?> idAndValue : subjectAltNames) {
                  if (idAndValue != null && idAndValue.size() == 2) {
                      if (idAndValue.get(0).equals(field)) {
                          return Optional.ofNullable(idAndValue.get(1));
                      }
                  }
              }
  
              return Optional.empty();
          } catch (CertificateParsingException e) {
              return Optional.empty();
          }
      }
docs: Extract the value of a given SubjectAltName field from a {@link X509Certificate}.
  
  @param certificate the certificate.
  @param field       the field number.
  @return an {@link Optional} containing the value in the field.
  @see #SUBJECT_ALT_NAME_IP_ADDRESS
  @see #SUBJECT_ALT_NAME_DNS_NAME
  @see #SUBJECT_ALT_NAME_URI