loop « enum « Java Data Type Q&A





1. for loop to iterate over enum in Java?    stackoverflow.com

I have an enum in Java for the cardinal & intermediate directions:

public enum Direction {
   NORTH,
   NORTHEAST,
   EAST,
   SOUTHEAST,
   SOUTH,
  ...

2. Java enum and loop question    stackoverflow.com

I have a list of Nodes which I loop through:

for (int i = 0; i < aNodes.getLength(); i++) {
  //
}
For example, assume the list contains 12 items, and that I ...

3. Loop for Enums in Java    stackoverflow.com

I have some enums like this:

public enum Classification {
    UNKNOWN("Unknown"),
    DELETION("Deletion"),
    DUPLICATION("Duplication"), ....
but some of them have like 20 members, so currently ...

4. looping through an enum?    coderanch.com

Rather than hand-typing each of the following enums, is there some way to loop through each value and read its .ordinal() value? @SuppressWarnings({ "unused", "null" }) //TODO: write ranking rules private static ArrayList getWinner(ArrayList _players) { ArrayList _winners = null; _winners.addAll(_players); long _handRanking = 0; int _highCardPoints = 0; long _totalScore = 0; boolean _rankingFound = false; /*TODO: 1. Player.setRanking(_ranking) for ...

5. While loop with enums    forums.oracle.com

Perhaps you could use an [EnumSet|http://java.sun.com/javase/6/docs/api/java/util/EnumSet.html] to specify the enum values on which you want to operate. It offers methods like range() and complementOf() that could be useful. Do you need enums? Why not have a button info class which holds the name, text position etc and iterate over a collection of these?