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 :: why we use return method 
Java :: matrix dimensions 
Java :: method overriding in java 
Java :: Split string into a string array 
Java :: arraylist sort 
Java :: list of arrays 
Java :: buy and sell stock 
Java :: instantiation in java 
Java :: |= java operation 
Java :: java meeting scheduler 
Java :: deep content 
Java :: Map - counting with map 
Java :: Method Overloading by changing the data type of parameters Java 
Java :: program Pr115_3; var k, n : integer; suma : real; begin readln(n); suma := 0; for k := 1 to n do suma := suma + 1 / sqr(2*k+1); writeln(suma); readln; end. 
Java :: execute a multi line shell comand in java 
Java :: convert kotlin code to java online 
Java :: how to create a sublist in java 
Java :: java default access modifier 
Java :: detect bluetooth headphones android programmatically 
Java :: layout focus from recycleview not from top in fragment inside nestedScrollview in android xml 
Java :: null check in line java 
Java :: java scanner class time 
Java :: How can I add a listener on the ok button of JOptionPane 
Java :: java mongodb document get 
Java :: find maximum number of rides in amusement park python 
Java :: how to call values from methods in flutter 
Java :: java Color on Enum call 
Java :: lcm 
Java :: how to come from 2nd fragment to first fragment android 
Java :: Bypass java web security permit All 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =