I am using an ArrayList
for a program, called wordList
. I have a separate ArrayList
for another method, called smallestWords
. I do "smallestWords = arrayList
" in order to have a copy of wordList
that I can modify without affecting the original. However, whenever I modify smallestWords
, it also modifies wordList
, which is causing me issues. I'm assuming it's because setting smallestWords
equal to wordList
just sets it equal to that memory location, since it's an abstract data type, and gets passed by reference.
How can I make it so I get a copy of the data without being able to modify it? If you want to see the actual code for the program just ask.