[JAVA] Item 58: Prefer for-each loops to traditional for loops

58. For-each loops should be selected over traditional for loops

package tryAny.effectiveJava;

import java.util.Arrays;
import java.util.Collection;

public class NestedFor {
    enum Suit {
        CLUB, DIAMOND, HEART, SPADE
    };

    enum Rank {
        ACE, DEUCE, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING
    };

    public static void main(String[] args) {
        Collection<Suit> suits = Arrays.asList(Suit.values());
        Collection<Rank> ranks = Arrays.asList(Rank.values());

        for (Suit suit : suits) {
            for (Rank rank : ranks) {
                System.out.println("Handle" + suit + ":number" + rank);
            }
        }
    }
}

Recommended Posts

Item 58: Prefer for-each loops to traditional for loops
Item 89: For instance control, prefer enum types to readResolve
Item 28: Prefer lists to arrays
Item 65: Prefer interfaces to reflection
Item 43: Prefer method references to lambdas
Item 42: Prefer lambdas to anonymous classes
Item 39: Prefer annotations to naming patterns
Item 85: Prefer alternatives to Java serialization
Item 23: Prefer class hierarchies to tagged classes
Item 61: Prefer primitive types to boxed primitives
Item 81: Prefer concurrency utilities to wait and notify
Item 80: Prefer executors, tasks, and streams to threads
[Java] How to make multiple for loops single
Item 47: Prefer Collection to Stream as a return type
Ruby Learning # 23 For Loops
Minecraft Modding [1.12] How to attach a special render for Item