How to code the set method of a Map with another Map as value?

Posted by Nazgulled on Stack Overflow See other posts from Stack Overflow or by Nazgulled
Published on 2010-05-27T20:06:07Z Indexed on 2010/05/27 20:11 UTC
Read the original article Hit count: 138

Filed under:
|
|
|

I normally do this to set a new Map to a private variable:

public static void setListaClausulas(Map<String, Clausula> nvLista) {
    listaClausulas = new TreeMap<String, Clausula>(nvLista);
}

I suppose this is ok to set a new copy of the nvLista and all it's members and not a reference, is it?

But now I have a Map inside another Map and I'm doing this:

public static void setListaClausulas(Map<String, Map<String, Clausula>> nvLista) {
    listaClausulas = new TreeMap<String, Map<String, Clausula>>(nvLista);
}

Is this the correct way to do it or do you recommend something else? What I want is to set a new copy of nvLista (and all it's elements) and not copy just the reference.

© Stack Overflow or respective owner

Related posts about java

Related posts about reference