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

Java Enum name()

name(SMALL)
// returns "SMALL"
Comment

PREVIOUS NEXT
Code Example
::  
Java :: get day from date month year java 
Java :: java calendar add minutes 
::  
Java ::  
:: testing the web layer without authentication spring 
Java ::  
Java :: spring swagger 
:: java stream get all max values 
Java :: find minimum in array java 
:: AndroidManifest.xml could not be found. 
Java :: hello world! java 
::  
Java ::  
Java :: java string to integer 
::  
Java ::  
:: nested list java 
Java ::  
Java ::  
Java :: get all keys from pbject javascirpt 
Java ::  
Java :: java list select field 
:: android dialog box example 
Java :: Java repeat last 3 letters of string 
:: how to initialize an empty array in java 
Java :: java repeat method 
Java ::  
Java :: java search arraylist 
::  
ADD CONTENT
Topic
Content
Source link
Name
2+7 =