Clean Solution in java


#1

import java.util.stream.Collectors;
public class Solution {
public ArrayList subUnsort(ArrayList A) {
ArrayList result = new ArrayList<>();
List sortedArray = A.stream().sorted().collect(Collectors.toList());
int startIndex = -1;
int endIndex = -1;

    for (int i = 0; i < sortedArray.size(); i++) {
        if (sortedArray.get(i).equals(A.get(i))) {
            continue;
        } else {
            if (startIndex == -1) startIndex = i;
            else endIndex = i;
        }
    }

    if (startIndex == -1) {
        result.add(-1);
    } else {
        result.add(startIndex);
        result.add(endIndex);
    }
    return result;
}

}