Find the longest ascending subarray from a given array I have following task, form a given array, I want the longest ascending array.
I will give you an example 

int[] a = {19,12,13,1,2,3,4,5,14,23,24,25,26,31,32};


will return array of {1,2,3,4,5} - that is the largest sequence of ascending numbers in the given array.

Below is the sample code:

int[] a = {19,12,13,1,2,3,4,5,14,23,24,25,26,27,31,32};
        List&lt;Integer&gt; longestArray = new ArrayList&lt;Integer&gt;();
        List&lt;Integer&gt; currentArary = new ArrayList&lt;Integer&gt;();              
        for (int i = 1; i &lt; a.length; i++) {
            if(currentArary.isEmpty()) {
                currentArary.add(a[i-1]);
            }
            if (a[i]-1 == a[i-1]) {
                currentArary.add(a[i]);
            } else {
                if(longestArray.size()&lt;currentArary.size()) {
                    longestArray.clear();
                    longestArray.addAll(currentArary);
                }
                currentArary.clear();
            }
        }
        System.out.println(longestArray);


Any feedback received on this method is more than welcome.
Josay provided a lot of good feedback, so I'll try to focus on something I think is very important.

There's no need to save the current subsequence

For your solution, you manage two lists, both of which are rewritten and cleared multiple times. Instead of doing this, we can just save where the largest subsequence starts, and how long it is. This can be stored in two integers. 

When looping, we also keep track of where the current subsequence started, and how long it is. Once it is broken, we simply compare the length to the previous maximum length, and update accordingly. I also added a check to handle sequences which are fully ascending (e.g. {1, 2, 3, 4, 5}).

public static int[] getLongestAscending(int[] a) {
    int maxLength = 0;
    int maxStart = 0;
    int length = 1;
    int start = 0;
    boolean fullAscension = true;
    for (int i = 1; i &lt; a.length; i++) {
        if (a[i]-1 == a[i-1]) {
            length++;
        } else {
            fullAscension = false;
            if (length &gt; maxLength) {
                maxLength = length;
                maxStart = start;
            }
            length = 1;
            start = i;
        }
    }
    if (fullAscension) {
        return a;
    }
    if (length &gt; maxLength) {
        maxLength = length;
        maxStart = start;
    }       int[] ret = new int[maxLength];
    System.arraycopy(a, maxStart, ret, 0, maxLength);
    return ret;
}


According to me, this is clearer, and saves all information needed. It also has the advantage of returning data on the same format as the input, and it is also quite a bit faster. From some benchmarks it seems to be about 20-30 times faster.