Can anybody explain why use of i>0 after && operator giving index out of bound exception while using it before isn’t


This Content is from Stack Overflow. Question asked by Aiyan Faras

enter image description here > this is giing arrayIndexOutOfBound Exception

  **       for(int i=0; i< arr.length; i++){
                    start =0;
                    if((arr[i]==arr[i-1]) && i>0){
                        start =  end+1;
                      end = outer.size()-1;**    
> This is working

                `for(int i=0; i< arr.length; i++){
                    start =0;
                    if(i>0 && (arr[i]==arr[i-1]) ){
                        start =  end+1;
                    end = outer.size()-1;



This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?