Sourav Sourav - 1 year ago 96
Java Question

When to use static initial block in JAVA?

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download