Java Preference Put putList(String path, ArrayList list)

Here you can find the source of putList(String path, ArrayList list)

Description

Put a list of strings to preferences.

License

Open Source License

Parameter

Parameter Description
path The absolute path name of the node.
list The list of strings.

Declaration

public static void putList(String path, ArrayList<String> list) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.prefs.Preferences;

public class Main {
    /** Put a list of strings to preferences.
    The list is stored as a size property end element_N properties with
    N being the element index.//ww  w.  j a  v a  2 s  . c  o m
    @param path The absolute path name of the node.
    @param list The list of strings. */
    public static void putList(String path, ArrayList<String> list) {
        Preferences prefs = createNode(path);
        if (prefs == null)
            return;
        prefs.putInt("size", list.size());
        for (int i = 0; i < list.size(); ++i)
            prefs.put("element_" + i, list.get(i));
    }

    /** Get node path, create if not already existing.
    @param path The absolute path name of the node.
    @return The node */
    public static Preferences createNode(String path) {
        assert !path.startsWith("/");
        return Preferences.userRoot().node(path);
    }
}

Related

  1. put(final String key, final boolean value)
  2. putBooleanDontOverwrite(Preferences prefs, String key, boolean value)
  3. putCLOB(Preferences prefs, String key, String clob)
  4. putPrefsBoolean(Preferences prefs, String key, boolean value, boolean def)
  5. putPrefsStrings(Preferences prefs, String key, String[] strings)
  6. setLocale(final Locale l)
  7. setPrefBoolean(Object context, final String key, final boolean value)