Java foreach跳过第一次迭代

Java foreach跳过第一次迭代

// One
cars.stream().skip(1).forEach(arr -> // do something );
// Two
for (Car car : cars.subList(1, cars.size())) {
     
    // do something
}
for (Car car : Iterables.skip(cars, 1)) {
     
	// do something
}
// Three
for (Car car : cars) {
     
	if (car == cars[0]) {
     
		continue;
	}
}
// Four
int counter = 0;
for (Car car : cars) {
     
	if (counter > 0) {
      // do something }
	counter++;
}

你可能感兴趣的:(Java,foreach跳过第一次迭代)