code: public static double length3D(CoordinateSequence pts) {
                  // optimized for processing CoordinateSequences
                  int n = pts.size();
                  if (n <= 1) {
                          return 0.0;
                  }
  
                  double len = 0.0;
  
                  Coordinate p = new Coordinate();
                  pts.getCoordinate(0, p);
                  double x0 = p.x;
                  double y0 = p.y;
                  double z0 = p.z;
  
                  if (Double.isNaN(z0)) {
                          return 0.0;
                  }
  
                  for (int i = 1; i < n; i++) {
                          pts.getCoordinate(i, p);
  
                          double x1 = p.x;
                          double y1 = p.y;
                          double z1 = p.z;
                          if (Double.isNaN(z1)) {
                                  return 0.0;
                          }
                          double dx = x1 - x0;
                          double dy = y1 - y0;
                          double dz = z1 - z0;
  
                          len += Math.sqrt(dx * dx + dy * dy + dz * dz);
                          x0 = x1;
                          y0 = y1;
                          z0 = z1;
                  }
                  return len;
          }
docs: Computes the length of a linestring specified by a sequence of points.
  if a coordinate has a NaN z return 0.
  
  @param pts
  the points specifying the linestring
  @return the length of the linestring