- Java.util Package Classes
- Java.util - Home
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util Package Extras
- Java.util - Interfaces
- Java.util - Exceptions
- Java.util - Enumerations
- Java.util Useful Resources
- Java.util - Useful Resources
- Java.util - Discussion
Java PropertyResourceBundle handleKeySet() Method
Description
The Java PropertyResourceBundle handleKeySet() method returns the set of keys this resource bundle (this does not include keys in parent bundle).
Declaration
Following is the declaration for java.util.PropertyResourceBundle.handleKeySet() method
protected Set<String> handleKeySet()
Parameters
NA
Return Value
This method returns keys of this and its parent bundles.
Exception
NA
Getting Keys from a PropertyResourceBundle Instance from ByteStream Example
The following example shows the usage of Java PropertyResourceBundle handleKeySet() method. We created a InputStream of given content and then using that stream a PropertyResourceBundle object is created. Then using handleKeySet() method, a set of keys is retrieved and entries are printed.
package com.tutorialspoint; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.StringBufferInputStream; import java.nio.charset.Charset; import java.util.PropertyResourceBundle; public class PropertyResourceBundleDemo { public static void main(String[] args) { // Prepare content for simulating property files String fileContent = "# Integer value 1\n" + "s1 = 1\n" + "# String value PropertyResourceBundleDemo\n" + "s2 = PropertyResourceBundleDemo\n" + "# Date value Fri Jan 31 00:00:00 IST 3913\n" + "s3 = Fri Jan 31 00:00:00 IST 3913"; InputStream propStream = new ByteArrayInputStream(fileContent.getBytes (Charset.forName("UTF-8"))); try { // Create property resource bundle PropertyResourceBundle bundle = new PropertyResourceBundle(propStream); // Get resource key set Set<String> keySet = bundle.handleKeySet(); Iterator<String> keys = keySet.iterator(); while(keys.hasNext()) { System.out.println("Bundle key: "+keys.next()); } } catch (IOException e) { e.printStackTrace(); } } }
Output
Let us compile and run the above program, this will produce the following result −
Bundle key: s2 Bundle key: s1 Bundle key: s3
Getting Keys from a PropertyResourceBundle Instance from StringReader Example
The following example shows the usage of Java PropertyResourceBundle handleKeySet() method. We created a StringReader of given content and then using that reader a PropertyResourceBundle object is created. Then using handleKeySet() method, a set of keys is retrieved and entries are printed.
package com.tutorialspoint; import java.io.IOException; import java.io.StringReader; import java.util.PropertyResourceBundle; public class PropertyResourceBundleDemo { public static void main(String[] args) { // Prepare content for simulating property files String fileContent = "# Integer value 1\n" + "s1 = 1\n" + "# String value PropertyResourceBundleDemo\n" + "s2 = PropertyResourceBundleDemo\n" + "# Date value Fri Jan 31 00:00:00 IST 3913\n" + "s3 = Fri Jan 31 00:00:00 IST 3913"; StringReader reader = new StringReader(fileContent); try { // Create property resource bundle PropertyResourceBundle bundle = new PropertyResourceBundle(reader); // Get resource key set Set<String> keySet = bundle.handleKeySet(); Iterator<String> keys = keySet.iterator(); while(keys.hasNext()) { System.out.println("Bundle key: "+keys.next()); } } catch (IOException e) { e.printStackTrace(); } } }
Output
Let us compile and run the above program, this will produce the following result −
Bundle key: s2 Bundle key: s1 Bundle key: s3
To Continue Learning Please Login
Login with Google