MainResourceBundle.java Source code

Java tutorial

Introduction

Here is the source code for MainResourceBundle.java

Source

import java.util.Enumeration;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.StringTokenizer;

class MainResourceBundle extends ResourceBundle {

    @Override
    public Object handleGetObject(String key) {
        if (key.equals("hello")) {
            return "Hello from java2s.com!";
        } else {
            return null;
        }
    }

    @Override
    public Enumeration getKeys() {
        StringTokenizer key = new StringTokenizer("Hello from java2s.com!");
        return key;
    }

}

public class Main {
    public static void main(String[] args) {

        ResourceBundle bundle = MainResourceBundle.getBundle("hello", Locale.US);

        System.out.println(bundle.getString("hello"));

    }
}