ricardoaux Posted March 11, 2012 at 06:05 PM Report Share #443413 Posted March 11, 2012 at 06:05 PM Boas Tenho duas arraylists: ArrayList<ArrayList<Integer>> array1 = new ArrayList<ArrayList<Integer>>(); ArrayList<Integer> array2 = new ArrayList<Integer>(); O que eu quero é adicionar elementos do array2 no array1.. faço: array1.add(array2); Mas está a adicionar um array vazio, em vez do conteúdo do array2 :S Como faço para conseguir adicionar o conteúdo do array2 ao array1??? Desde já agradeço a ajuda. Link to comment Share on other sites More sharing options...
KTachyon Posted March 11, 2012 at 07:48 PM Report Share #443430 Posted March 11, 2012 at 07:48 PM Adicionaste alguma coisa ao array2? O que estás a fazer funciona perfeitamente: ArrayList<ArrayList<Integer>> array1 = new ArrayList<ArrayList<Integer>>(); ArrayList<Integer> array2 = new ArrayList<Integer>(); ArrayList<Integer> array3 = new ArrayList<Integer>(); array2.add(1); array2.add(3); array3.add(4); array3.add(6); array1.add(array2); array1.add(array3); for (ArrayList<Integer> a : array1) { System.out.println("A imprimir array:"); for (int b : a) { System.out.println(b); } } “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare 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