Programming & Development / April 11, 2025

How to Represent Sri Lanka's Provinces in Java and SQL with Official Codes

Sri Lanka provinces Java enum ISO 3166-2 LK SQL table Spring Boot enum Sri Lanka address validation provinces in Sri Lanka ISO codes Sri Lanka address validation regions of Sri Lanka

🇱🇰 Java Enum: Sri Lanka's Provinces with ISO Codes

This Java enum represents all 9 provinces of Sri Lanka using their official ISO 3166-2:LK codes.

java

public enum SriLankaProvince {
    CENTRAL("1"),
    EASTERN("2"),
    NORTHERN("3"),
    NORTH_WESTERN("4"),
    SOUTHERN("5"),
    WESTERN("6"),
    UVA("7"),
    SABARAGAMUWA("8"),
    NORTH_CENTRAL("9");

    private final String code;

    SriLankaProvince(String code) {
        this.code = code;
    }

    public String getCode() {
        return code;
    }
}

Usage Example:

java

SriLankaProvince province = SriLankaProvince.CENTRAL;
System.out.println(province.getCode()); // Outputs: 1

🗃️ SQL Version: Sri Lanka's Provinces Table

Here’s the SQL schema and insert statements for creating a table to represent the provinces of Sri Lanka.

sql

CREATE TABLE sri_lanka_provinces (
    id SERIAL PRIMARY KEY,
    name VARCHAR(64) NOT NULL,
    code CHAR(1) NOT NULL UNIQUE
);

Insert Statements:

sql

INSERT INTO sri_lanka_provinces (name, code) VALUES
('Central', '1'),
('Eastern', '2'),
('Northern', '3'),
('North Western', '4'),
('Southern', '5'),
('Western', '6'),
('Uva', '7'),
('Sabaragamuwa', '8'),
('North Central', '9');

✅ Summary

Representing Sri Lanka’s provinces with Java enums and relational SQL tables ensures consistent handling of regional data. By using ISO 3166-2:LK codes, we maintain international standards and ease of integration across systems.


Comments

No comments yet

Add a new Comment

NUHMAN.COM

Information Technology website for Programming & Development, Web Design & UX/UI, Startups & Innovation, Gadgets & Consumer Tech, Cloud Computing & Enterprise Tech, Cybersecurity, Artificial Intelligence (AI) & Machine Learning (ML), Gaming Technology, Mobile Development, Tech News & Trends, Open Source & Linux, Data Science & Analytics

Categories

Tags

©{" "} Nuhmans.com . All Rights Reserved. Designed by{" "} HTML Codex