Unable to figure out the problem in the code It says Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6 I have gone through it a lot of times,still unable to figure whats wrong
Note: Trying to sort 0, 1 in an array
public class javaarray {
    public static void main(String[] args) {
        int[] arr = new int[]{1, 0, 0, 1, 1, 0}; 
        int left = 0, right =arr.length-1;
        while(left<right) {
            while(arr[left]==0 && left<right) {
                left++;
            }
            while(arr[right]==1 && left<right){
                right++;
            }
            if(left<right) {
                arr[left]=0;
                arr[right]=1;
                left++;
                right--;
              }  
           }
           for(int i=0; i<arr.length;i++) {
               System.out.print(arr[i]) 
           }
       }
    }
}
 
     
     
     
    