aspose file tools*
The moose likes Beginning Java and the fly likes ArrayListS in an ArrayList that consists of ArrayListS behave like they are the same instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ArrayListS in an ArrayList that consists of ArrayListS behave like they are the same instance" Watch "ArrayListS in an ArrayList that consists of ArrayListS behave like they are the same instance" New topic
Author

ArrayListS in an ArrayList that consists of ArrayListS behave like they are the same instance

merve klug
Greenhorn

Joined: Oct 07, 2009
Posts: 17

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.

here is manupulation code:



after the line:



denemeKombinasyonuCumleKelimesiListesiListesi[0]
denemeKombinasyonuCumleKelimesiListesiListesi[1]
denemeKombinasyonuCumleKelimesiListesiListesi[1]
denemeKombinasyonuCumleKelimesiListesiListesi[3]

all have become affected.

please pay attention
"it is not problem" of denemeKombinasyonuCumleKelimesiListesiListesi[i] and cka both affected,

"the problem is all the elements of arraylist are affected".

please share what you think.
thanks in advance.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3649
    
  17

Hi Merve,

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
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.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3649
    
  17

Can you please post an SSCCE that demonstrates your problem?
merve klug
Greenhorn

Joined: Oct 07, 2009
Posts: 17
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: 3018
    
  10
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
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
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://aspose.com/file-tools
 
subject: ArrayListS in an ArrayList that consists of ArrayListS behave like they are the same instance