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 :: how to give square in java 
Java :: java random double between 0 and 1 
Java :: java mail use tls 1.2 
Java :: flink prometheus alert on failed jobs 
Java :: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver 
Java :: java memory increase command 
Java :: java end scripting 
Java :: input long in java 
Java :: how to update java runtime 
Java :: what is maven artifact 
Java :: kubectl config kubernetes dashboard 
Java :: greater than sign in java 
Java :: java print default options 
Java :: convert int to byte java 
Java :: Java Longest String In String Array 
Java :: find highest value in keyset java 
Java :: java int array to integer arraylist 
Java :: import java.lang.Math.*; 
Java :: logging in java 
Java :: if and else on one line java 
Java :: spark write partitionby 
Java :: work with arrays java 
Java :: java initialize object array 
Java :: how to sort arraylist 
Java :: import javafx 
Java :: findone in spring boot 2.4.1 
Java :: what are abstract methods in java 
Java :: Java path to file 
Java :: java spring username encode and decode 
Java :: Java How to use Map? 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =