Louise Posted May 21, 2008 at 06:58 PM Report Share #186524 Posted May 21, 2008 at 06:58 PM Boas Eu tenho um hashMap em k a chave é um objecto e os valores é um array. Existe alguma forme de eu ir adicionando elementos a esse array??? Ou so a martelo retirando kom o metodo get o array adicionar o elemento, apanhar aquela chave do hashmap e voltar a meter. private HashMap<No, Aresta[]> mapas; . . . mapas.put(n, null);//inicialmente só conheço os nós depois a medida que encontrar arestas keria as inserir Obrigada Link to comment Share on other sites More sharing options...
Rui Carlos Posted May 21, 2008 at 07:28 PM Report Share #186533 Posted May 21, 2008 at 07:28 PM Sendo um array uma referência, a única coisa que tens que fazer, é ir buscar o seu valor, e adicionares o novo elemento. Não é necessário voltar a inseri-lo. Isto se tiveres o array já inicializado, é claro... Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
Louise Posted May 21, 2008 at 07:48 PM Author Report Share #186542 Posted May 21, 2008 at 07:48 PM Sendo um array uma referência, a única coisa que tens que fazer, é ir buscar o seu valor, e adicionares o novo elemento. Não é necessário voltar a inseri-lo. Isto se tiveres o array já inicializado, é claro... Não percebi mt bem. tipo isto: (mapas.get(n))[0]=a; Pois eu devo ter de mudar akilo pra uma lista pk nao sei kantas arestas vao ser pra inicializar. Entao ficaria (mapas.get(n)).add(a); Link to comment Share on other sites More sharing options...
Rui Carlos Posted May 21, 2008 at 07:51 PM Report Share #186543 Posted May 21, 2008 at 07:51 PM Sim, isso deve funcionar. Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now