Java single for loop


#1
public ArrayList<Integer> rotateArray(ArrayList<Integer> A, int B) {
    int size = A.size();
    if(B>=size){
        B = B%size;
    }
    ArrayList<Integer> ret = new ArrayList<Integer>();
    for (int i = 0; i < A.size(); i++) {
        int index = (i+B)>=size?i+B-size:i+B;
        ret.add(i, A.get(index));
    }
    return ret;
}