code: public static double JaccardDistance(double[] p, double[] q) {
          double distance = 0;
          int intersection = 0, union = 0;
  
          for (int x = 0; x < p.length; x++) {
              if ((p[x] != 0) || (q[x] != 0)) {
                  if (p[x] == q[x]) {
                      intersection++;
                  }
  
                  union++;
              }
          }
  
          if (union != 0)
              distance = 1.0 - ((double) intersection / (double) union);
          else
              distance = 0;
  
          return distance;
      }
docs: Gets the Jaccard distance between two points.
  
  @param p A point in space.
  @param q A point in space.
  @return The Jaccard distance between x and y.