I have an array of int type, I want check that array to see if it has equal elements for example: {1,1,1,1,1} return true, otherwise false. I have written this code, it works well but I want know if its good or there better algorithm.
Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names, with a first and a last name.
You can edit your display name here. Thank you for your prompt attention!
-Marc
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
There appear to be two different ideas here about what is meant by "check an array for equality". Gary and (maybe) Scott are talking about checking if two different arrays are equal to each other, in the sense that the corresponding elements are equal. I.e. a[0] == b[0], a[1] == b[1], etc. But the original poster and others are talking about checking one array to see if all the elements are equal to each other. I.e. a[0] == a[1] == a[2] etc. These are completely different problems; let's not mix them up.
The orignal problem I have is to check a grid of elements modeled as 2D array to see if 1 row or column has equal elements. However checking 1D array seems different.