Home >Java >javaTutorial >What does values mean in java
values() is a static method of the enumeration type in Java, used to obtain an array containing all the constants of the enumeration, arranged in the order of declaration. Specifically: Returns a typed array containing the enumeration constants. The elements in the array are arranged in the order in which the enumeration is declared. Methods are static and can be called without creating an instance. There is only one values() array per enumeration type. The values of enumeration constants cannot be modified.
The meaning of Values in Java
In Java, values()
is a Static method for obtaining a constant array of enumeration type. It is an important part of the enumeration type and is used to access the fixed values defined by the enumeration.
Function
##values() The method returns an array containing all the constants of the enumeration, and its type is an array of the enumeration type. The elements in the array are arranged in the order in which the enumeration is declared.
Syntax
<code class="java">public static T[] values()</code>Where:
Returns
Example
Consider the following enumeration type:<code class="java">public enum Season { SPRING, SUMMER, FALL, WINTER }</code>We can get the enumeration using the
values() method All constants in the example:
<code class="java">Season[] seasons = Season.values();</code>Now, the
seasons array will contain the following elements:
<code>[SPRING, SUMMER, FALL, WINTER]</code>
Notes
The method is static and therefore can be called directly from the class level without creating an instance of the class.
array exists.
array cannot be modified.
The above is the detailed content of What does values mean in java. For more information, please follow other related articles on the PHP Chinese website!