Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Java Enum

enum Size {
   SMALL, MEDIUM, LARGE, EXTRALARGE
}

class Main {
   public static void main(String[] args) {
      System.out.println(Size.SMALL);
      System.out.println(Size.MEDIUM);
   }
}
Comment

Java Enums

public class Main {
  enum Level {
    LOW,
    MEDIUM,
    HIGH
  }

  public static void main(String[] args) {
    Level myVar = Level.MEDIUM; 
    System.out.println(myVar);
  }
}
Comment

java enum

package org.o7planning.tutorial.javaenum;

public enum Color {
  RED("red") {
      @Override
      public String getHexCode() {
          return "#ff0000";
      }
  },
  GREEN("green") {
      @Override
      public String getHexCode() {
          return "#00ff00";
      }
  },
  BLUE("blue") {
      @Override
      public String getHexCode() {
          return "#0000ff";
      }
  };
  private String name;
  Color(String name) {
      this.name = name;
  }
  public String getName() {
      return name;
  } 
  public abstract String getHexCode();
}
Comment

enum java

private enum VarState {
	INIT, 
	TRUE, 
  	FALSE,
	UNSATISFIABLE 
}
Comment

java enum

public class DaysOfTheWeek {

    public enum Days {m, t, w, r, f, sat, s};
  	    public static void main(String[] args) {
          Days d = Days.t; 
          System.out.println(d);
          //the output would be t
        }
}
Comment

java enum

package vn.viettuts.javaenum;
 
public enum PageInfo {
    // define enum with 3 variable
    PAGE_001("PAGE_001", "Login", "/login"), 
    PAGE_002("PAGE_002", "Add new user", "/addUser"), 
    PAGE_003("PAGE_003", "List user", "/listUser");
     
    private String pageID;
    private String pageTitle;
    private String pageURL;
     
    /**
     * constructor
     * 
     * @param pageID
     * @param pageTitle
     * @param pageURL
     */
    private PageInfo(String pageID, String pageTitle, String pageURL) {
        this.pageID = pageID;
        this.pageTitle = pageTitle;
        this.pageURL = pageURL;
    }
     
    // getter & setter
    public String getPageID() {
        return pageID;
    }
 
    public void setPageID(String pageID) {
        this.pageID = pageID;
    }
 
    public String getPageTitle() {
        return pageTitle;
    }
 
    public void setPageTitle(String pageTitle) {
        this.pageTitle = pageTitle;
    }
 
    public String getPageURL() {
        return pageURL;
    }
 
    public void setPageURL(String pageURL) {
        this.pageURL = pageURL;
    }
}
Comment

java enum

package vn.viettuts.javaenum;
 
public class EnumExample5 {
    // define days of week
    enum Day {
        MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, 
        SATURDAY, SUNDAY
    }
 
    public static void main(String args[]) {
        Day day = Day.SUNDAY;
 
        switch (day) {
        case SUNDAY:
            System.out.println("sunday");
            break;
        case MONDAY:
            System.out.println("monday");
            break;
        default:
            System.out.println("other day");
        }
    }
}
Comment

java enum


package vn.viettuts.javaenum;
 
public class EnumExample5 {
    // define enum Season
    enum Season {
        SPRING(5), SUMMER(10), FALL(15), WINTER(20);
 
        private int value;
 
        private Season(int value) {
            this.value = value;
        }
    }
 
    public static void main(String args[]) {
        for (Season s : Season.values()) {
            System.out.println(s + " " + s.value);
        }
    }
}
Comment

java enum

package org.o7planning.tutorial.javaenum;

public enum Currency {
  VND, USD, EURO ;

  @Override
  public String toString() {
      if (this == VND) {
          return "Dong";
      } else if (this == USD) {
          return "Dola";
      }
      return super.toString();
  }
  public static void main(String[] args) {
      Currency money = Currency.USD;
      System.out.println("Money " + money);
      System.out.println("Money " + money.toString());
      System.out.println("VND " + Currency.VND);
      System.out.println("EURO " + Currency.EURO);
  }
}
Comment

Java enums

enum Size { 
   SMALL, MEDIUM, LARGE, EXTRALARGE 
}
Comment

Enum Class in Java

enum Size {
    constant1, constant2, …, constantN;

    // methods and fields	
}
Comment

PREVIOUS NEXT
Code Example
Java :: find highest value in keyset java 
Java :: convert array of char to string java 
Java :: what is lambda expression in java 
Java :: how to use a combo box in java with if else 
Java :: map in java 
Java :: android setTextColor not working 
Java :: export JAVA_HOME=` mac 
Java :: jmeter get var 
Java :: recursion in java 
Java :: continue in java 
Java :: initialize an array in java 
Java :: Java Create an OutputStream 
Java :: java netbeans textfield only numbers 
Java :: prime number program in java 
Java :: java create file 
Java :: how to initialize a string in java 
Java :: save bitmap file for share on android 10 
Java :: java localdate subtract two dates 
Java :: if else statement 
Java :: For loop Java Example to Iterate an Array 
Java :: Syntax of how to create ArrayList in Java 
Java :: convert object array to int array java 
Java :: how to create object of abstract class in java 
Java :: java string vers int 
Java :: Java How to use Map? 
Java :: java calendar 
Java :: public static void main(String[] args) in java 
Java :: run webgoat using docker 
Java :: long to double in java 
Java :: locked screen android studio 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =