Reputation: 41
I need to write a method taking that only parameter is a reference to an array of references to values, and return true if the references stored in the array refer to the same exact number object.
Does "reference to an array of references to values" mean just "array of something"? like Type[] a = new Type[]; ?
And, how do I check the number object stored in the array? I guess I need to use the for loop?
Upvotes: 1
Views: 19
Reputation: 311823
You could iterate over the array and check if all the objects are ==
to each other:
public static boolean allSame(Object[] arr) {
for (int i = 1; i < arr.length; ++i) {
if (arr[i] != arr[0]) {
return false;
}
}
return true;
}
Upvotes: 1