Let's say I have an array of objects like dummies[] below. I want to find the index of array objects where their attribute a == 5 or a > 3 etc.
class Dummy{
int a;
int b;
public Dummy(int a,int b){
this.a=a;
this.b=b;
}
}
public class CollectionTest {
public static void main(String[] args) {
//Create a list of objects
Dummy[] dummies=new Dummy[10];
for(int i=0;i<10;i++){
dummies[i]=new Dummy(i,i*i);
}
//Get the index of array where a==5
//??????????????????????????????? -- WHAT'S BEST to go in here?
}
}
Is there any way other than iterating over the array objects and check for the conditions? Does using ArrayList or other type of Collection help here?
dummiesto a new array.a==5?