Here you can find the source of getList(String path)
Parameter | Description |
---|---|
path | The absolute path name of the node. |
public static ArrayList<String> getList(String path)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.prefs.Preferences; import java.util.prefs.BackingStoreException; public class Main { /** Get a list of strings from preferences. The list is stored as a size property end element_N properties with N being the element index./*from w w w. j av a 2 s . co m*/ @param path The absolute path name of the node. @return The list of strings. */ public static ArrayList<String> getList(String path) { Preferences prefs = getNode(path); if (prefs == null) return new ArrayList<String>(); int size = prefs.getInt("size", 0); if (size <= 0) return new ArrayList<String>(); ArrayList<String> result = new ArrayList<String>(size); for (int i = 0; i < size; ++i) { String element = prefs.get("element_" + i, null); if (element == null) // Should not happen break; result.add(element); } return result; } /** Get node for package and path, return null if not already existing. @param path The absolute path name of the node. @return The node or null, if node does not exist or failure in the backing store. */ public static Preferences getNode(String path) { assert !path.startsWith("/"); Preferences prefs = Preferences.userRoot(); try { if (!prefs.nodeExists(path)) return null; } catch (BackingStoreException e) { return null; } return prefs.node(path); } }