Link to home
Start Free TrialLog in
Avatar of chaitu chaitu
chaitu chaituFlag for India

asked on

how can i assign one arraylist to another

 if(breakBulkHouseModel.getChargesList()!=null)
                   {
                        breakBulkHouseModel.getChargesList().addAll(breakBulkHouseModel.getViewChargesList());
                                                                             
                   }
                    else
                {
                }


                       

                 
        how can i assign one arraylist  to another if  breakBulkHouseModel.getChargesList() is null
like breakBulkHouseModel.getChargesList() =breakBulkHouseModel.getViewChargesList();


after that i will do like this

if(breakBulkHouseModel.getChargesList() != null)
              {
             for(int j=0;j<breakBulkHouseModel.getChargesList().size();j++)
                {
                                                ...........................
            }

            }

Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

You can either assign or copy (of which you gave an example). What is the difficulty?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chaitu chaitu

ASKER

in some cases   breakBulkHouseModel.getChargesList() will come null then i want to assign   breakBulkHouseModel.getChargesList() to  breakBulkHouseModel.getViewChargesList() ;


in my application i am doing

 breakBulkHouseModel.getChargesList().addAll(breakBulkHouseModel.getViewChargesList());

if  breakBulkHouseModel.getChargesList() will come null i am getting nullpointer exception;

at that time i want assign

tChargesList() =ViewChargesList();

if(breakBulkHouseModel.getChargesList()!=null)
                   {
                        for(Iterator k=breakBulkHouseModel.getChargesList().iterator();k.hasNext();)
                        {
                                HouseDocumentCharges      viewCharges      =      (HouseDocumentCharges)k.next();
                             if(breakBulkHouseModel.getViewChargesList()!=null)
                             {
                                for(Iterator j=breakBulkHouseModel.getViewChargesList().iterator();j.hasNext();)
                                {
                                     HouseDocumentCharges      charges      =      (HouseDocumentCharges)j.next();
                                    if(charges.chargeId.equals(viewCharges.chargeId) || !charges.chargeId.equals("045"))
                                    {
                                        j.remove();
                                        continue;
                                    }
                                           
                                }
                             }                            
                        }
                        if(breakBulkHouseModel.getChargesList() != null && breakBulkHouseModel.getViewChargesList() != null)
                        breakBulkHouseModel.getChargesList().addAll(breakBulkHouseModel.getViewChargesList());
                                                                             
                   }
                    else
                  breakBulkHouseModel.getChargesList().addAll(breakBulkHouseModel.getViewChargesList());

              if i am doing  like this i am getting nullpointer exception because  breakBulkHouseModel.getChargesList() comes nulll

              at that time i want to assign

breakBulkHouseModel.getChargesList() =breakBulkHouseModel.getViewChargesList();
                                                                             
                 
                       

                 
         if(breakBulkHouseModel.getChargesList() != null)
              {
             for(int j=0;j<breakBulkHouseModel.getChargesList().size();j++)
                {
                    houseDocumentCharges =(HouseDocumentCharges)breakBulkHouseModel.getChargesList().get(j);

                    }

                }
See my code above. You could also simply assign getViewChargesList to 'cl' in the else block if you want
:-)

Actually you can do just

cl = new ArrayList(breakBulkHouseModel.getViewChargesList());