Passed ArrayList is getting updated + Java

Amoumboilla

New Member
I have a question that I can't figure out right now. I have a class as Iframe which has the variable "private List pathContainer" to maintain the path of the Iframe.Given is the code of it,\[code\]public class IFrame implements HtmlElement {private WebElement elem;private String xpath;private boolean selected;private String parentClass;private boolean isProcessed=false;private boolean isIframeContent=false;private List <String> pathContainer; public IFrame(WebElement elem) { this.elem = elem; pathContainer=new ArrayList<String>();}\[/code\]I'm passing the path list of a parent iframe to a sub iframe to include it in it's list. But when ever I modify the subIframe path list, the parent Iframe pathlist also gets changed. Given is the code of the function,\[code\]public void LoadIFrameNodes(List<String> parentPath){ IFrame iframe=new IFrame(e); List <String> tempPath=new ArrayList<String>(); iframe.setPathContainer(parentPath); //assigning parent path in subIframe list tempPath=iframe.getPathContainer(); tempPath.add(iframe.getXpath()); // add another value to subIframe iframe.setPathContainer(tempPath); //setting the changed list as the subIframe }\[/code\]Once the the subIframe is set with the new values, the passed parentPath list also gets changed with the new values. I don't the passed list to be updated. Please let me know where it went wrong?
 
Back
Top