I've come up with two ways to check to see if array is sorted and return true if it is.public static boolean checkSortedness(int[] data){    for(int i = 1; i < data.length; i++)    {        if(data[i-1] > data[i])        {            return false;        }    }    return true;}I've also seen the i start at 0 and compare the next element instead of the previous. The other way which involves another variable ispublic static boolean isSorted(int[] data){     int previous = data[0];     for(int i = 1; i < data.length; i++)     {         if(previous > data[i])             return false;         previous = data[i];     }     return true;}Which way is better and are there any alternatives?What should the array parameter be named? I call it data but I've  considered arr. This class is meant to be fairly generic.
Checking if an array is sorted
java;array;sorting;comparative review
The better way would be your first, as you're just comparing the element A with element B and not creating a copy of the element as you are in the second version. Additionally, to be a bit of a pedant - you don't want to name a function checkSortedness where its only returning a boolean, over isSorted where its assumed it would return a boolean.public static boolean isSorted(int[] data){    for(int i = 1; i < data.length; i++){        if(data[i-1] > data[i]){            return false;        }    }    return true;}