1

I was wondering if there is an easy way to convert the javafx.util.Properties object to a java.util.HashMap.

There is the obvious way of getting each value from the Properties object and putting it in a Map. But with a large number of properties it seems like there should be a way of just getting the Map that backs javafx.util.Properties (if it is a Map).

Thanks in advance for any suggestions.

2 Answers 2

1

I don't really know if javafx.util.Properties are backed by Java Map, but since public API does not mention any way to get this map you probably shouldn't try to do it - even if it was possible (e.g. by extending Properties class) it might change in future versions.

I would stay with copying every element.

Sign up to request clarification or add additional context in comments.

Comments

0

+1 for pazabos answer. But I would go the other way around: extend HashMap or java.util.Properties which then could export javafx.util.Properties (or hold an instance) sth. like:

class MyProperties extends HashMap {
    HashSet<String> keys = new HashSet<String>();
    javafx.util.Properties p = new Properties();

    public String get(String str) {
        return p.get(str);
    }

    public Map creatHashMap() {
        Map map = new HashMap();
        for (String k : keys) {
            map.put(k, p.get(k));
        }
        return map;
    }

    public void put() {
        //...
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.