On Mon, 24 Jan 2005 14:29:21 +0530, Sudheer <[EMAIL PROTECTED]> wrote: > Hi friends, > > I have a method like this, the 3rd param, category contains > ArrayList of classes Category. > > Here I am copying the Category class from the ArrayList to > lALCategories (Line 11) and storing its property name into a > local variable lsName (Line15) and doing some processing and > writing it back on line 19. > > Then adding this class to lALOutPut. Here the changes I made > to the class property name is reflected in HashMap category > also. I don't want the changes to be reflected in the passed > HashMap category. How do I do this? Please help.
This is pretty basic Java. Java is pass by reference, so there is only one copy of the ICCategory. If you want multiple copies your going to have to clone it. > > TIA > > Sudheer > > 01. public static ArrayList listTree(Integer parentID, HashMap tree, HashMap > category) > 02. { > 03. Category lCCategory = null; > 04. ArrayList lALCategories = new ArrayList(), lALOutPut = new > ArrayList(); > 05. Integer liNext = null; > 06. Integer liTree[] = (Integer[]) tree.get(parentID); > 07. String lsName = ""; > 08. for (short liElm = 0; liElm < liTree.length; liElm++) > 09. { > 10. liNext = liTree[liElm]; > 11. lALCategories = (ArrayList) category.get(liNext); > 12. for (int liIElm = 0; liIElm < lALCategories.size(); liIElm++) > 13. { > 14. lCCategory = (Category) lALCategories.get(liIElm); > 15. lsName = lCCategory.getName() > 16. /* > 17. Some processing here on lsName. > 18. */ > 19. lCCategory.setName(lsName); > 20. lALOutPut.add(lCCategory); > 21. } > 22. } > 23. return lALOutPut; > 24.} > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]