This TestCode is supposed to create an stream of numbers in seconds. Collect 10 samples, and average the time which each samples comes out. I did try to use if-else, but the variable from if doesn't share with else. Please correct me if I'm wrong. I don't understand lambda just yet.
public class TestCode {
    private int eachTwoSec;
    // supposed to aList.add 10 items
    // average the time needed in between each aList.add (2 obviously)
    public void avgTimeTaken() {
        ArrayList aList = new ArrayList();
        for (int i = 0; i < 10; i++) {
            aList.add(eachTwoSec);
        }
    }
    // return a number every two seconds (endless stream of samples)
    // samples 50,52,54,56,58,60,2,4,6,8,10
    public void twoSecTime() {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException ex) {
            Logger.getLogger(Dummies.class.getName()).log(Level.SEVERE, null, ex);
        }
        LocalDateTime ldt = LocalDateTime.now();
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("ss");
        eachTwoSec = Integer.parseInt(ldt.format(dtf));
        System.out.println(eachTwoSec);
        twoSecTime();
    }
    public TestCode() {
        // construct
        avgTimeTaken();
        new Thread(this::twoSecTime).start();
    }
    public static void main(String[] args) {
        // just a start point
        new TestCode();
    }
}