Hello I have a Class for Global Variables. One of the Functions within that Class is used to clear one of my ArrayList's. The only issue, is that it is clearing Two of my ArrayLists and I can't figure out why. All it is suppose to clear is m_listItems.
Before the Clear Runs: https://i.stack.imgur.com/dN5n4.png
After the Clear Runs: https://i.stack.imgur.com/5eKfj.png
This function adds the ArrayList "m_listItems" to the double Array List.
public void addGrouptoList(){
ArrayList myArray = Global.m_listItems;
Global.groupCollection.add(myArray);
}
This function should clear ONLY m_listItems but it clears both:
public void ClearNameList(){
Global.m_listItems.clear();
}
This is how I created the two ArrayList's
private static ArrayList<ArrayList<String>> groupCollection= new ArrayList<>();
private static ArrayList<String> m_listItems = new ArrayList<String>();
Any Help would be much appreciated. Whether it be a work around or why its messing up!
EDIT I have done a lot of googling and I think the issue is because I'm doing add(global.m_list_items), so when i clear m_list_items, it clears it in my other array also... is there a work around for this? I read that Static is what is causing the issue but I need that for my global variable. I can't seem to find a workaround in google.
Thanks!