ResourceBundle bundle = ResourceBundle.getBundle("myResources"); Enumerationkeys = bundle.getKeys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); System.out.println(key + " = " + bundle.getString(key)); }
ResourceBundle bundle = ResourceBundle.getBundle("myResources"); if (bundle.containsKey("greeting")) { String greeting = bundle.getString("greeting"); System.out.println(greeting); }In this example, we are checking if a key named "greeting" exists in the resource bundle named "myResources". If the key exists, we retrieve its value using the getString() method of the ResourceBundle class and print it out. These examples use the java.util package, which is part of the Java Standard Library.