code: public static double autocorrelation(FlatDataList flatDataList, int lags) {
          int n = count(flatDataList);
          if(n<=0 || lags<=0 || n<lags) {
              throw new IllegalArgumentException("All the parameters must be positive and n larger than lags.");
          }
          
          FlatDataCollection flatDataCollection = flatDataList.toFlatDataCollection();
          double mean = mean(flatDataCollection);
          double variance = variance(flatDataCollection, true);
          
          double Ak=0.0;
          
          int maxI=n-lags;
          for(int i=0;i<maxI;++i) {
              Ak += (flatDataList.getDouble(i) - mean)*
                    (flatDataList.getDouble(i+lags) - mean);
          }
          
          Ak/=(n-lags);
          
          double autocorrelation = Ak/variance;
          
          return autocorrelation;
      }
docs: Calculates the autocorrelation of a flatDataCollection for a predifined lag
  
  @param flatDataList
  @param lags
  @return