What is a for each loop? - Cracking the Java Coding Interview

preview_player
Показать описание
Cracking the #Java #Coding #Interview - Question 137: What is a for each loop?
Рекомендации по теме
Комментарии
Автор

I didn't know JVM drop it at the end.
Very good and simple explanation! Merci bcp

bluehelion
Автор

the forEach(Consumer) method *can* be faster. The default impl in Iterable does indeed just use for-each, but a specific iterable impl can (if its author isn't lazy and it's a win) take advantage of its access to the internal data structure to do better... (the point about the jvm possibly optimising out the implicit iterator may make it harder for a specific impl to do better though). i tend to use forEach() in preference on the offchance.

StrangerNoises
Автор

It can sometimes even be the only way to iterate through something. For example a map has no way of being iterated by index.

redcrafterlppa
Автор

I've never commented on a video before, but I had to for this one. It's that good!

MyCodingDiary
Автор

En parlant de l'itérateur pourquoi java n'utilise pas plus la class Enumeration<T> ? En effet il serait pratique d'avoir un typage pour un itérateur qui ne permettrait que la lecture d'une collection, au lieu d'utiliser un itérateur qui offre la l'opération .remove()

petitmoi
Автор

In the comming future is goto statement be added in Java?

akrk
Автор

The only thing I wish the JVM would accept is this:
for(String entry : () -> list.iterator()) {}
Sadly it doesn't.

Point is, sometimes you just have a iterator, so using a lambda to trick into a Iterable would be really cool.

Speiger
Автор

Thumbs up if you agree that this video is amazing!

MyCodingDiary
Автор

I have an idea for the next java tip
Java Coding Tip #138:
How to migrate to kotlin

rebok
visit shbcf.ru