{"id":13361,"date":"2020-10-25T15:23:11","date_gmt":"2020-10-25T22:23:11","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=13361"},"modified":"2023-12-01T04:03:22","modified_gmt":"2023-12-01T12:03:22","slug":"java-enum","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/java-enum\/","title":{"rendered":"How to Use Enum in Java"},"content":{"rendered":"\n<p><em>A Java enum is a data type that stores a list of constants. You can create an enum object using the enum keyword. Enum constants appear as a comma-separated list within a pair of curly brackets.<\/em><\/p>\n\n\n\n<p>An enum, which is short for enumeration, is a data type that has a fixed set of possible values.<\/p>\n\n\n\n<p>Enums are useful if you\u2019re working with a value that should only hold a specific value that is contained within a list of values. For instance, an enum would be used if you wanted to store a list of coffee sizes sold at a store.&nbsp;<\/p>\n\n\n\n<p>This tutorial will walk through the basics of enums in Java. We\u2019ll refer to a few examples of an enum class in a Java program to help you get started. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Java Enum Syntax<\/h2>\n\n\n\n<p>A Java enum represents a list of constants. A variable assigned from an enum can only have a value that appears in the enum. Enums help developers store data that they know will not change.<\/p>\n\n\n\n<p>Let&#8217;s say you decide that a <a href=\"https:\/\/careerkarma.com\/blog\/java-variables\/\">Java variable<\/a> that stores employee pay grades can only have one of five values. Or, you decide a variable that stores employee contracts can only store <em>Part-time<\/em>, <em>Full-time<\/em>, or <em>Zero-hours.<\/em> In these cases, you would want to use an enum to store data.<\/p>\n\n\n\n<p>Enums are declared using the \u201c<em>enum<\/em>\u201d type. Here\u2019s the syntax of the \u201c<em>enum<\/em>\u201d keyword:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>enum name {\n\tVALUE1, VALUE2, VALUE3\n}\n<\/pre><\/div>\n\n\n\n<p>Let\u2019s break down this syntax:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>enum<\/strong> tells our program we want to declare an enumeration.<\/li><li><strong>name<\/strong> is the name of our enum.<\/li><li><strong>VALUE1, VALUE2, VALUE3<\/strong> are the set of constant values our enum stores. These values are usually written in uppercase.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Why Use Enums in Java?<\/h2>\n\n\n\n<p>Using enums allows you to express an algorithm in a more readable way to both yourself and the computer.<\/p>\n\n\n\n<p>Writing an enum tells the computer a variable can only have a specific number of values. It also tells you, the coder, that this is the case, which will make it easier to understand your code. If you see a variable that uses an enum, you know that the variable can only have one of a limited number of values.<\/p>\n\n\n\n<p>Additionally, enums allow you to more effectively use constants. In fact, enum was introduced to replace <em>int<\/em> constants in Java, which spanned multiple lines and were difficult to read. Here\u2019s an example of an old <em>int<\/em> constant in Java:<\/p>\n\n\n\n<p>Our code takes up five lines to declare these constants. But by using an enum, we can reduce our code to three lines. In the example below, we declare a list of enum constants:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>class IntConstant {\n\tpublic final static int ECONOMY = 1;\n\tpublic final static int BUSINESS = 2;\n\tpublic final static int FIRST_CLASS = 3;\n}\n<\/pre><\/div>\n\n\n\n<p>Our code takes up five lines to declare these constants. But by using an enum, we can reduce our code to three lines. In the example below, we declare a list of enum constants:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>class AirplaneClasses {\n\tECONOMY, BUSINESS, FIRST_CLASS\n}\n<\/pre><\/div>\n\n\n\n<p>This code is simpler and easier to read.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Declaring a Java Enum<\/h2>\n\n\n\n<p>We are building an app that wait staff can use to submit a coffee order to the baristas at a coffee shop.<\/p>\n\n\n\n<p>When a barista inserts a value for the size of the drink, we only want there to be three possible options. These options are: SMALL, REGULAR, and LARGE. We could use an enum to limit the possible sizes of a drink to those options:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>enum Sizes {\n\tSMALL, REGULAR, LARGE\n}\n<\/pre><\/div>\n\n\n\n<p>In this example, we have declared an enum called <em>Sizes<\/em> which has three possible values. Now that we have declared an enum, we can refer to its values in our code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Java Enum Example<\/h2>\n\n\n\n<p>We are writing a program that prints out the size of coffee a customer has ordered to the console. This value will be read by the barista who prepares the customer\u2019s drink.<\/p>\n\n\n\n<p>We could use the following code to print out the size of the coffee a customer has ordered to the console:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>enum Sizes {\n\tSMALL, REGULAR, LARGE\n}\n\nclass PrintSize {\n\tSizes coffeeSize;\n\t\n\tpublic PrintSize(Sizes coffeeSize) {\n\t\tthis.coffeeSize = coffeeSize;\n\t}\n\n\tpublic void placeOrder() {\n\t\tswitch(coffeeSize) {\n\t\t\tcase SMALL:\n\t\t\t\tSystem.out.println(&quot;This coffee should be small.&quot;);\n\t\t\t\tbreak;\n\t\t\tcase REGULAR:\n\t\t\t\tSystem.out.println(&quot;This coffee should be REGULAR.&quot;);\n\t\t\t\tbreak;\n\t\t\tcase LARGE:\n\t\t\t\tSystem.out.println(&quot;This coffee should be large.&quot;);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\nclass Main {\n\tpublic static void main(String[] args) {\n\t\tPrintSize order173 = new PrintSize(Sizes.SMALL);\n\t\torder173.placeOrder();\n\t}\n}\n<\/pre><\/div>\n\n\n\n<p>Our code returns:<br><\/p>\n\n\n\n<p><code>This coffee should be small.<\/code><\/p>\n\n\n\n<p>First, we declare an enum called Sizes. This enum can have three values: SMALL, REGULAR, or LARGE. Next, we declared a class called PrintSize. This class accepts the size of the customer\u2019s drink and prints out the drink size to the console.\n\n<\/p>\n\n\n\n<p>In our main program, we declare an object called <em>order173<\/em>,\u201d which uses the PrintSize class. We passed the <a href=\"https:\/\/careerkarma.com\/blog\/java-methods\/\">Java <\/a><a href=\"https:\/\/careerkarma.com\/blog\/java-methods\/\">parameter<\/a> Sizes.SMALL through our code. This tells our program to assign the value SMALL to the variable <em>coffeeSize<\/em> in the PrintSize class.\n\n<\/p>\n\n\n\n<p>Then we use <em>order173.placeOrder()<\/em> to execute the code within the <em>switch case<\/em> statement in the PrintSize class. This evaluates the value of the \u201ccoffeeSize\u201d variable against three cases. A message is printed to the console depending on the size of the coffee a customer has ordered.\n\n<\/p>\n\n\n\n<p>We specified that the customer ordered a small coffee. Our code prints out, &#8220;<em>This coffee should be small.&#8221;<\/em> to the console.\n\n<\/p>\n\n\n\n<p>If you\u2019re looking to learn more about Java switch case statements, you can read about them in our tutorial on the <a href=\"https:\/\/careerkarma.com\/blog\/java-switch-statement\">Java switch statement<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Java Enum Methods<\/h2>\n\n\n\n<p>The Java enum class includes a number of predefined methods that are used to retrieve and manipulate values that use the enum class. Below we have broken down five of the most commonly used enum methods.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">compareTo()<\/h3>\n\n\n\n<p>compareTo() compares the constants in an enum lexicographically and returns the difference between their ordinal values. Here\u2019s an example of compareTo() being used with an enum value from our above example:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>int difference = Sizes.SMALL.compareTo(Sizes.LARGE);\nSystem.out.println(difference);\n<\/pre><\/div>\n\n\n\n<p>Our code returns the difference between the <code>SMALL<\/code> and <code>LARGE<\/code> strings based on their ordinal value. In this case, our code returns:<br><\/p>\n\n\n\n<p><code>-2<br><\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">toString()<\/h3>\n\n\n\n<p>toString() converts the name of an enum to a string. Here\u2019s an example of toString() being used to convert the <code>LARGE<\/code> enum value to a string:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>String large_string = LARGE.toString();\nSystem.out.println(large_string);\n<\/pre><\/div>\n\n\n\n<p>Our code returns:<br><\/p>\n\n\n\n<p><code>\u201cLARGE\u201d<br><\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">name()<\/h3>\n\n\n\n<p>The name() method returns the name used to define a constant in an enum class. Here\u2019s an example of the name() method being used to return the defined name of the REGULAR coffee size:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>String regular_name = name(REGULAR);\nSystem.out.println(regular_name);\n<\/pre><\/div>\n\n\n\n<p>Our code returns:<br><\/p>\n\n\n\n<p><code>\u201cREGULAR\u201d<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">values()<\/h3>\n\n\n\n<p>The values() method returns a <a href=\"https:\/\/careerkarma.com\/blog\/java-array\/\"><\/a><a href=\"https:\/\/careerkarma.com\/blog\/java-array\/\">Java array<\/a> which stores all the constants in an enum. Here\u2019s an example of the values() method in action:<\/p>\n\n\n\n<p><code>Sizes[] sizeList = Sizes.values();<br><\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">valueOf()<\/h3>\n\n\n\n<p>valueOf() accepts a string and returns the enum constant, which has the same name. So, if we wanted to retrieve the enum constant with the name <code>REGULAR,<\/code> we could do so using this code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>String regular_constant = Sizes.valueOf(&quot;REGULAR&quot;);\nSystem.out.println(regular_constant);\n<\/pre><\/div>\n\n\n\n<p>Our code returns:<br><\/p>\n\n\n\n<p><code>REGULAR<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>An enum, short for an enumeration, is a Java data type that has a fixed set of values.<\/p>\n\n\n\n<p>Enums are useful if you are working with variables that should only be capable of storing one out of a select range of values.<\/p>\n\n\n\n<p>After practicing what you have read in this tutorial, you\u2019ll be an expert at using enums in Java. To learn more about coding in Java, read our complete guide on <a href=\"https:\/\/careerkarma.com\/blog\/how-to-code-in-java\/\">How to Code in Java<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"A Java enum is a data type that stores a list of constants. You can create an enum object using the enum keyword. Enum constants appear as a comma-separated list within a pair of curly brackets. An enum, which is short for enumeration, is a data type that has a fixed set of possible values.&hellip;","protected":false},"author":240,"featured_media":13359,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[17289],"tags":[],"class_list":{"0":"post-13361","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-java"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Java","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Use Enum in Java: The Complete Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"We use the Java enum class to declare data types with a fixed set of possible values. Learn more in this Career Karma article.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/java-enum\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Use Enum in Java\" \/>\n<meta property=\"og:description\" content=\"We use the Java enum class to declare data types with a fixed set of possible values. Learn more in this Career Karma article.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/java-enum\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-10-25T22:23:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T12:03:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/man-working-on-a-laptop-while-woman-takes-notes-3153208.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"667\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/java-enum\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/java-enum\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"How to Use Enum in Java\",\"datePublished\":\"2020-10-25T22:23:11+00:00\",\"dateModified\":\"2023-12-01T12:03:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/java-enum\/\"},\"wordCount\":1126,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/java-enum\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/man-working-on-a-laptop-while-woman-takes-notes-3153208.jpg\",\"articleSection\":[\"Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/java-enum\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/java-enum\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/java-enum\/\",\"name\":\"How to Use Enum in Java: The Complete Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/java-enum\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/java-enum\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/man-working-on-a-laptop-while-woman-takes-notes-3153208.jpg\",\"datePublished\":\"2020-10-25T22:23:11+00:00\",\"dateModified\":\"2023-12-01T12:03:22+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"We use the Java enum class to declare data types with a fixed set of possible values. Learn more in this Career Karma article.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/java-enum\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/java-enum\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/java-enum\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/man-working-on-a-laptop-while-woman-takes-notes-3153208.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/man-working-on-a-laptop-while-woman-takes-notes-3153208.jpg\",\"width\":1000,\"height\":667},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/java-enum\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\/\/careerkarma.com\/blog\/java\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Use Enum in Java\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Use Enum in Java: The Complete Guide | Career Karma","description":"We use the Java enum class to declare data types with a fixed set of possible values. Learn more in this Career Karma article.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/java-enum\/","og_locale":"en_US","og_type":"article","og_title":"How to Use Enum in Java","og_description":"We use the Java enum class to declare data types with a fixed set of possible values. Learn more in this Career Karma article.","og_url":"https:\/\/careerkarma.com\/blog\/java-enum\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-10-25T22:23:11+00:00","article_modified_time":"2023-12-01T12:03:22+00:00","og_image":[{"width":1000,"height":667,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/man-working-on-a-laptop-while-woman-takes-notes-3153208.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/java-enum\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/java-enum\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"How to Use Enum in Java","datePublished":"2020-10-25T22:23:11+00:00","dateModified":"2023-12-01T12:03:22+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/java-enum\/"},"wordCount":1126,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/java-enum\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/man-working-on-a-laptop-while-woman-takes-notes-3153208.jpg","articleSection":["Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/java-enum\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/java-enum\/","url":"https:\/\/careerkarma.com\/blog\/java-enum\/","name":"How to Use Enum in Java: The Complete Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/java-enum\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/java-enum\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/man-working-on-a-laptop-while-woman-takes-notes-3153208.jpg","datePublished":"2020-10-25T22:23:11+00:00","dateModified":"2023-12-01T12:03:22+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"We use the Java enum class to declare data types with a fixed set of possible values. Learn more in this Career Karma article.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/java-enum\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/java-enum\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/java-enum\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/man-working-on-a-laptop-while-woman-takes-notes-3153208.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/man-working-on-a-laptop-while-woman-takes-notes-3153208.jpg","width":1000,"height":667},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/java-enum\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/careerkarma.com\/blog\/java\/"},{"@type":"ListItem","position":3,"name":"How to Use Enum in Java"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/13361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=13361"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/13361\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/13359"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=13361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=13361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=13361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}