How to Get keys from Preferences

From Java Example Source Code

Jump to: navigation, search

Contents

[edit] Overview - How to Get keys from Preferences

This Java example program shows how to get keys from Preferences.

[edit] Java Source Code

  • Package: example.preferenceproperties
  • File: PreferenceExample2.java
package example.preferenceproperties;
 
import java.util.prefs.Preferences;
 
public class PreferenceExample {
    public static void main(String args[]) throws Exception {
	Preferences prefsRoot = Preferences.userRoot();
	Preferences myPrefs = prefsRoot.node("PreferenceExample");
 
	myPrefs.put("A", "a");
	myPrefs.put("B", "b");
	myPrefs.put("C", "c");
 
	System.out.print("Node's keys: ");
	for (String s : myPrefs.keys()) {
	    System.out.print(s + "");
	}
    }
}

[edit] What Result You Can Get

Run the program, you will get:

Node's keys: ABC

[edit] Required External Libraries and/or Files for this Java Example

Need nothing.


[edit] How to Run this Java Example Program

We recommend running this Java example program with Eclipse.

For assistance in working with Eclipse, please see How to Run Java Program with Eclipse.

It's fairly easy.



[edit] Question & Answer

Any question?

Click edit and post your question or answer here.


Personal tools