Sourav Sourav - 7 months ago 52
Java Question

When to use static initial block in JAVA?

Can anyone please explain me in which scenario we use static initial block?


You can use it as a "constructor" for static data in your class. For example, a common situation might be setting up a list of special words:

private static final Set<String> special = new HashSet<String>();
static {

These can then be used later to check if a string matches something interesting.