Counting pairs of elements in a circular ArrayList containing -1, 0, and 1
The 2nd way is to use the array with unique index calculated from current and next value:

public void test() {

    List&lt;Integer&gt; slopeChanges = new ArrayList&lt;Integer&gt;();
    slopeChanges.add(0);
    slopeChanges.add(0);
    slopeChanges.add(1);
    slopeChanges.add(0);
    slopeChanges.add(1);

    /*
    static final int count_neg10 = 2; // -1 + 3 * (0 + 1);
    static final int count_neg11 = 5; // -1  + 3 * (1 + 1);
    static final int count_10 = 4; // 1 + 3 * (0 + 1);
    static final int count_1neg1 = 1; // 1 + 3 * (-1 + 1);
    static final int count_0neg1 = 0; // 0  + 3 * (-1 + 1);
    static final int count_01 = 6; // 0  + 3 * (1 + 1);*/

    int[] count = {0, 0, 0, 0, 0, 0, 0};
    String[] count_names = {"count_0neg1", "count_1neg1", "count_neg10", "", "count_10", "count_neg11", "count_01"};

    List&lt;Double&gt; sixProbabilites = new ArrayList&lt;Double&gt;();

    for(int i = 0, j = slopeChanges.size() -1; i&lt;slopeChanges.size(); i++) {
      if (slopeChanges.get(i) != slopeChanges.get(j)) {
        count[slopeChanges.get(i) + 3 * (slopeChanges.get(j) + 1) ]++;
      } 
      j = i;
    }

    System.out.println(slopeChanges);

    for(int i = 0; i&lt;7; i++) {
      if(count[i] != 0) {
        System.out.println(count_names[i] + " = " + count[i]);
        sixProbabilites.add((double)count[i] / ((double)slopeChanges.size()));
      }
    }
}