Hi,
You can clone the Category object implementanting the
java.lang.Cloneable interface (see the java api documentation) and
correct the code in the following way:

> 12.      for (Iterator iterator = lALCategories.iterator();
iterator.hasNext(); )
> 13.      {
> 14.        lCCategory = ((Category) iterator.next()).clone();
> 15.    lsName = lCCategory.getName()
> 16.    /*
> 17.    Some processing here on lsName.
> 18.    */
> 19.        lCCategory.setName(lsName);
> 20.        lALOutPut.add(lCCategory);
> 21.      }

BR
/Amleto

> -----Messaggio originale-----
> Da: Sudheer [mailto:[EMAIL PROTECTED] 
> Inviato: luned́ 24 gennaio 2005 9.59
> A: Struts Users Mailing List
> Oggetto: OT newbie - java class question
> 
> 
> 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.
> 
> 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.}
> 
> -- 
> No virus found in this incoming message.
> Checked by AVG Anti-Virus.
> Version: 7.0.300 / Virus Database: 265.7.2 - Release Date: 21/01/2005
>  
> 

-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.2 - Release Date: 21/01/2005
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to