Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size of Enumeration<String>

Tags:

java

How can I get the size of an Enumeration<String> without iterate over it?

While debugging I can see the size of the the enumeration but I can't find a way to get this value.

like image 290
Ami Hollander Avatar asked Feb 26 '17 07:02

Ami Hollander


People also ask

How do you determine enumeration size?

You can do Collections. list(enumerationObject). size(); to get the number of elements. This creates a list.

How many values should an enum have?

An enumeration. A string object that can have only one value, chosen from the list of values 'value1', 'value2', ..., NULL or the special '' error value. In theory, an ENUM column can have a maximum of 65,535 distinct values; in practice, the real maximum depends on many factors.

What is difference between enum and enumeration?

enum is a syntactic sugar that allows for meaningful constants; Enumeration is a class that provides way to go through a collection.

What is enumeration in Java with example?

An enum type is a special data type that enables for a variable to be a set of predefined constants. The variable must be equal to one of the values that have been predefined for it. Common examples include compass directions (values of NORTH, SOUTH, EAST, and WEST) and the days of the week.


1 Answers

The Enumeration interface does not expose its size, and some (many?) implementations indeed do not have this knowledge. Without any knowledge of the specific implementation, you have no choice but to iterate over it.

like image 94
Mureinik Avatar answered Sep 30 '22 04:09

Mureinik