user762579
user762579

Reputation:

android ArrayList iterator

I am trying to use an iterator on an ArrayList ( to get rid of a for loop, don't ask me why... ), however I need to skip the process of one of the arrays upon a boolean condition , should I still use an index and a break ???

// INTERPOLATION
int i = 0;
Iterator<CircularFifoQueue<SensorEvent>> buf = samplingFifoQueues.iterator();
while (buf.hasNext()) {
    if ( i == 2 && !mDeviceSensorGyro) {  // skip this queue if no gyroscope in device
       break;
    }               
    // proceed
   buf.next();
   i++;
}

thanks for help

Upvotes: 0

Views: 311

Answers (1)

Gangnus
Gangnus

Reputation: 24484

What about this:

// INTERPOLATION
int i = 0;
Iterator<CircularFifoQueue<SensorEvent>> buf = samplingFifoQueues.iterator();
while (buf.hasNext()) {
    if ( i != 2 || mDeviceSensorGyro) {  // skip this queue if no gyroscope in device
       // proceed  
    }               

    buf.next();
    i++;
}

But I would rather attach some attribute to the queue elements to check for it. Work directly with numbers is bad practice.

Upvotes: 1

Related Questions