What is the fastest way to get the selected objects from an array?
MyObject[] objects = new MyObject[]{new MyObject(true), new MyObject(false)};
MyObject[] selectedObjects = ???
Is there a faster way than:
ArrayList<MyObject> selObjectsList = new ArrayList<MyObject>();
for(MyObject obj : objects){
if(obj.isSelected()){
selObjectsList.add(obj);
}
}
selectedObjects = selObjectsList.toArray(new MyObject[0]);
This are many lines for a simple operation, is there a shorter operation to do the same?