Merge pull request #6292 from pcoates33/BAEL-2527
BAEL-2527 Add section to Java enum iteration article
This commit is contained in:
commit
e49d46d240
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.variable.scope.examples;
|
package com.baeldung.scope;
|
||||||
|
|
||||||
public class BracketScopeExample {
|
public class BracketScopeExample {
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.variable.scope.examples;
|
package com.baeldung.scope;
|
||||||
|
|
||||||
public class ClassScopeExample {
|
public class ClassScopeExample {
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.variable.scope.examples;
|
package com.baeldung.scope;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.variable.scope.examples;
|
package com.baeldung.scope;
|
||||||
|
|
||||||
public class MethodScopeExample {
|
public class MethodScopeExample {
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.variable.scope.examples;
|
package com.baeldung.scope;
|
||||||
|
|
||||||
public class NestedScopesExample {
|
public class NestedScopesExample {
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,43 @@
|
||||||
package com.baeldung.java.enumiteration;
|
package com.baeldung.java.enumiteration;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public class EnumIterationExamples {
|
public class EnumIterationExamples {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("Enum iteration using forEach:");
|
System.out.println("Enum iteration using EnumSet:");
|
||||||
EnumSet.allOf(DaysOfWeekEnum.class).forEach(day -> System.out.println(day));
|
EnumSet.allOf(DaysOfWeekEnum.class).forEach(day -> System.out.println(day));
|
||||||
|
|
||||||
System.out.println("Enum iteration using Stream:");
|
System.out.println("Enum iteration using Stream:");
|
||||||
DaysOfWeekEnum.stream().filter(d -> d.getTypeOfDay().equals("off")).forEach(System.out::println);
|
DaysOfWeekEnum.stream().filter(d -> d.getTypeOfDay().equals("off")).forEach(System.out::println);
|
||||||
|
|
||||||
System.out.println("Enum iteration using for loop:");
|
System.out.println("Enum iteration using a for loop:");
|
||||||
for (DaysOfWeekEnum day : DaysOfWeekEnum.values()) {
|
for (DaysOfWeekEnum day : DaysOfWeekEnum.values()) {
|
||||||
System.out.println(day);
|
System.out.println(day);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println("Enum iteration using Arrays.asList():");
|
||||||
|
Arrays.asList(DaysOfWeekEnum.values()).forEach(day -> System.out.println(day));
|
||||||
|
|
||||||
|
System.out.println("Add Enum values to ArrayList:");
|
||||||
|
List<DaysOfWeekEnum> days = new ArrayList<>();
|
||||||
|
days.add(DaysOfWeekEnum.FRIDAY);
|
||||||
|
days.add(DaysOfWeekEnum.SATURDAY);
|
||||||
|
days.add(DaysOfWeekEnum.SUNDAY);
|
||||||
|
for (DaysOfWeekEnum day : days) {
|
||||||
|
System.out.println(day);
|
||||||
|
}
|
||||||
|
System.out.println("Remove SATURDAY from the list:");
|
||||||
|
days.remove(DaysOfWeekEnum.SATURDAY);
|
||||||
|
if (!days.contains(DaysOfWeekEnum.SATURDAY)) {
|
||||||
|
System.out.println("Saturday is no longer in the list");
|
||||||
|
}
|
||||||
|
for (DaysOfWeekEnum day : days) {
|
||||||
|
System.out.println(day);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue