ArrayListS in an ArrayList that consists of ArrayListS behave like they are the same instance
merve klug
Greenhorn
Joined: Oct 07, 2009
Posts: 17
posted
0
I am turkish and my variable names are turkish. i hope it won't be a problem.
here is the code:
as you can see there is an arraylist of arraylists of "cumlekelimesi" objects.
i fill the arraylist of arraylist with a templist: "geciciListe". i reconstruct the geciciListe with "new ArrayList<CumleKelimesi>()" at every step.
i can see that lists are filled with the values i wanted, all of them are different.
but when i try to manipulate the arraylists in te arraylist one by one, all the arraylists are effected.
How can you tell they're all affected? Are you testing after the while loop? If so, isn't it logical all the elements would be affected, since you call the method on each of them in the loop?
I would also highly recommend switching to English identifiers. You should always write your code so that other people can understand it, and getting help is a *lot* easier if you use English.
I don't mean to be uppity or anything; I used to write all my identifiers in Dutch. But switching to English will make life a lot more easy for you too.
merve klug
Greenhorn
Joined: Oct 07, 2009
Posts: 17
posted
0
hi,
yes i am debugging and testing after each iteration of the loops.
and arraylists in the arraylist of arraylists are affected even they are the list in the loop in that iteration or not.
Can you please post an SSCCE that demonstrates your problem?
merve klug
Greenhorn
Joined: Oct 07, 2009
Posts: 17
posted
0
hi,
thanks very much for attention
i wll be out for a few hours but i hope i will be see the problem while preparing sscce,
Mike Simmons
Ranch Hand
Joined: Mar 05, 2008
Posts: 2770
2
posted
0
We have no way of knowing what
does. You don't show that code. If the problem shows up immediately after that line, there's a good chance we will want to know what that line does.
Also it would be nice to know what "affected" means here. What effect are you seeing? Why is that a problem? I agree with all Stephan's questions and comments here.
merve klug
Greenhorn
Joined: Oct 07, 2009
Posts: 17
posted
0
hi,
first of all thanks for your time
is it important what Ayristirici.ayristirmaAlgoritmasi(cka) does?
when i want to debug into ayristirmaAlgoritmasi NetBeans show me only the cka and its sub elements.
thus, could the outer arraylist's other element how could be affected?
i am really confused.
in c maybe i can arrive some place out of array but i m in java(
i am going to make a manual debugging like writing system.out.println() between the lines.
thanks again.
merve klug
Greenhorn
Joined: Oct 07, 2009
Posts: 17
posted
0
hi,
problem has been solved.
when i defining a new object with
i was using the constructer
i changed the code with
in a forum it has been told to me to "deep copy" my arraylists
now i see, i must "deep copy" the "member lists" too.
thanks for all your time
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: ArrayListS in an ArrayList that consists of ArrayListS behave like they are the same instance